先上代码:
AssetManager mgr = DeviceListActivity.this.getApplicationContext().getAssets();
try {
Log.e("Glenn:", address);
FileOutputStream fout = mgr.openFd("device/device_address.txt").createOutputStream();
PrintWriter _fout = new PrintWriter(fout);
_fout.println(address);
Log.e("Glenn", address);
_fout.close();
fout.close();
InputStream fin = mgr.open("device/device_address.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fin));
address = br.readLine();
try {
Log.e("Glenn:", address);
} catch (NullPointerException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
Log.e("Glenn", "error with OutputStream");
}
前两次调用打印的地址值Log.e()
是正确的值,实际上是一个设备MAC地址。但是,当我试图测试从刚刚写入的文件中读取的地址值时,NullPointerException
已在Log.e()
调用中捕获。这意味着从文件中读取的值为NULL
. 谁能指出代码有什么问题?