-2
嘿這個代碼的人我寫了一個JSON文件,然後我想讀它。但是每次我想要閱讀時,我都會回覆這樣的內容:「[B @ ea6df」。每次都有其他答案。我做錯了什麼?從JSOn文件獲取weired回答
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());
}
}
你能給我一個Exemple如何Object.toString()的作品? –
在你的問題中有一個例子:「[B @ ea6df」([B代表一個字節數組,'ea6df'代表哈希代碼] Docu:https://docs.oracle.com/javase/8/docs /api/java/lang/Object.html#toString-- – Henry