为什么这么做:
FileWriter fw = new FileWriter("/data/data/com.myapp.client/files/myfile.json", true/*append*/);
在一些设备上(大多数都工作正常),我收到了:/data/data/com.myapp.client/files/myfile.json (No such file or directory)。如何避免此错误?
/data/data/com.myapp.client/files/myfile.json (No such file or directory)
不要硬编码路径,请改用Context.getFilesDir
Context.getFilesDir
File file = new File(context.getFilesDir(), "file.json")
请参见this以供参考。