奇怪的 Android FileNotFoundException: (只读文件系统)

问题描述

File dir = getDir("foo",Context.MODE_PRIVATE);
File f = new File(dir,"debug.xml");
Serializer serializer = new Persister();
serializer.write(myobject,f);

上面的代码通常可以正常工作。偶尔(很少),它会抛出以下异常:

java.io.FileNotFoundException
 Stack trace: java.io.FileNotFoundException: /mnt/expand/.../user/0/app.mydomain.net/app_foo/debug.xml (Read-only file system)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:287)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:223)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    at org.simpleframework.xml.core.Persister.write(SourceFile:1198)

谁能解释一下这个异常的可能原因。我认为 Context.getDir() 会提供一个可写的目录。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)