-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