2017-03-24 1 views
-2

이 코드의 Hey Guys 저는 JSON 파일을 작성한 후 그것을 읽고 싶습니다. 그러나 내가 읽고 싶을 때마다 나는 다음과 같은 것을 얻을 수 있습니다 : "[B @ ea6df". 매번 또 다른 대답. 내가 뭘 잘못 했니?JSOn 파일에서 답을 얻으십시오.

public void writeFile(Context context, String mJsonResponse) { 
    String file_name = "login_datas.json"; 
    try { 
     FileWriter file = new FileWriter(context.getFilesDir().getPath() + "/" + file_name); 
     file.write(mJsonResponse); 
     file.flush(); 
     file.close(); 
    } catch (IOException e) { 
     Log.e("TAG", "Error in Writing: " + e.getLocalizedMessage()); 
    } 
} 

public void readFile(Context context) { 
    try { 
     String file_name = "login_datas.json"; 
     File f = new File(context.getFilesDir().getPath() + "/" + file_name); 
     //check whether file exists 
     FileInputStream is = new FileInputStream(f); 
     int size = is.available(); 
     byte[] buffer = new byte[size]; 
     is.read(buffer); 
     is.close(); 
     Toast.makeText(LoginActivity.this,buffer.toString(),Toast.LENGTH_LONG).show(); 
    } catch (IOException e) { 
     Log.e("TAG", "Error in Reading: " + e.getLocalizedMessage()); 
    } 
} 

답변

1

buffer.toString() 당신이 생각하는대로하지 않습니다. 바이트 배열의 내용을 쓰지 않지만 객체의 클래스 이름과 해시 코드를 16 진수로 표시하는 일반 Object.toString() 메서드를 사용합니다.

+0

Object.toString() 작동 방식을 설명해 주시겠습니까? –

+0

"[B @ ea6df"([B는 바이트 배열을 나타내며 "ea6df"는 해시 코드입니다.) Docu : https://docs.oracle.com/javase/8/docs /api/java/lang/Object.html#toString-- – Henry