在我的android应用程序中,我在txt文件中记录错误。但是,当我试图创建文件时,我会遇到一个错误Java.io.IOException: open failed: EROS( Read Only file system error)。我在AndroidManifest.xml中添加了写权限,但没有区别。怎么修呢?
码
try {
File file =new File("Log.txt");
if(!file.exists()){
file.createNewFile();
}
catch (Exception e)
{
Log.w("tun tun", e.toString());
}发布于 2014-05-01 11:02:43
这样做
将存储在外部存储(SDCARD)上
try {
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "Log.txt");
if (!file.exists()) {
file.createNewFile();
}
} catch (Exception e) {
Log.w("tun tun", e.toString());
}将存储在内部存储中
try {
File file = new File(context.getCacheDir() + File.separator + "Log.txt");
if (!file.exists()) {
file.createNewFile();
}
} catch (Exception e) {
Log.w("tun tun", e.toString());
}发布于 2014-05-01 11:10:30
试试下面的代码:-
问题是您没有添加路径。
String filePath = context.getFilesDir().getPath().toString() + "/fileName.txt";
File f = new File(filePath);或
String FILENAME = "hello_file";
String string = "hello world!";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();参照系
或
path = Environment.getExternalStorageDirectory();
File file = new File(path, "/" + fname);https://stackoverflow.com/questions/23406303
复制相似问题