-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());
}
}
Object.toString() 작동 방식을 설명해 주시겠습니까? –
"[B @ ea6df"([B는 바이트 배열을 나타내며 "ea6df"는 해시 코드입니다.) Docu : https://docs.oracle.com/javase/8/docs /api/java/lang/Object.html#toString-- – Henry