【问题标题】:error:open fail:EROFS(Read-only file system) [duplicate]错误:打开失败:EROFS(只读文件系统)[重复]
【发布时间】:2014-07-20 15:09:49
【问题描述】:

我想为写/读创建文件

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView text=(TextView) findViewById(R.id.Hello);
    String str="my name is ";
    String FileName="myFile";
    File f=new File(FileName);
    try {
        if(!f.exists())
        {
            Boolean result= f.createNewFile();
            text.setText(result.toString());
        }
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        text.setText(e1.getMessage());
    }
}

清单

<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

但是说错误:打开失败:EROFS(只读文件系统)

我使用这个模拟器:

这是模拟器的错误吗!?

【问题讨论】:

    标签: android file text io android-emulator


    【解决方案1】:

    尝试检查 createNewFile() 是否成功。

    boolean result = f.createNewFile();
    

    如果文件已经存在,上面的结果将是错误的。如果您想确保创建了一个新文件,请尝试:

    f.delete()
    boolean result = f.createNewFile();
    

    还要确保之前的 setText()(例如“文件创建错误”)未被覆盖,因为您的异常处理不会停止后续代码的执行。

    【讨论】:

    • 先捕获说错误:打开失败:EROFS(只读文件系统)
    • 试试这个:# mount -o rw,remount /system.完成后,执行以下操作:# mount -o ro,remount /system。这样,您可以将文件系统挂载为读写。
    • 我是初学者,请多解释一下,如何 mount -o rw?我使用 avd 和 eclipse 来运行应用程序
    • 没有。不要重新挂载 /system - 你通常不能这样做,即使你可以应用程序代码也不允许在那里写,也不应该尝试这样做。问题是发布者试图将他们的文件写入不合适的位置,可能是设备的根目录,因为没有指定任何其他位置。
    猜你喜欢
    • 2015-06-08
    • 2014-06-01
    • 2015-01-22
    • 1970-01-01
    • 2014-04-19
    • 2019-09-30
    • 2012-12-08
    • 1970-01-01
    • 2016-01-23
    相关资源
    最近更新 更多