java.io.FileNotFoundException:stack.txt:open失败:EROFS(只读文件系统)
编辑:在跟进这两个建议的同时,我确定以下方法可以将字符串作为字节数组写入文件。但是现在我需要弄清楚如何将字节数组读回字符串。我需要你的帮助。。。 是否存在与此FileOutputStream相反的FileInputStream组件?这适用于将字符串写入字节数组java.io.FileNotFoundException:stack.txt:open失败:EROFS(只读文件系统),java,android,filenotfoundexception,fileoutputstream,dataoutputstream,Java,Android,Filenotfoundexception,Fileoutputstream,Dataoutputstream,编辑:在跟进这两个建议的同时,我确定以下方法可以将字符串作为字节数组写入文件。但是现在我需要弄清楚如何将字节数组读回字符串。我需要你的帮助。。。 是否存在与此FileOutputStream相反的FileInputStream组件?这适用于将字符串写入字节数组 try { FileOutputStream fos = openFileOutput("stack.txt", Context.MODE_PRIVATE); for (String item : st
try {
FileOutputStream fos = openFileOutput("stack.txt", Context.MODE_PRIVATE);
for (String item : stack)
fos.write(stack.pop().getBytes());
fos.close();
sb.append("The Stack is saved.\n");
} catch (IOException e) {
sb.append(e.toString());
}
displayText(sb.toString());
我正在尝试将字符串从ArrayQue写入文件。我将ArrayQue用作堆栈。这些弦的长度各不相同。我在打开文件进行输出时遇到此错误
java.io.FileNotFoundException: stack.txt: open failed: EROFS (Read-only file system)
我想我已经看到了所有关于这个话题的帖子,但是没有任何帮助。
我的两个代码片段是:
在做一些研究时,我感觉问题可能是我还不熟悉使用新应用程序特定的、持久的内部/外部存储的要求?但是我不知道,所以我正在寻找一些指导,请:)这是一个完整的问题解决方案的概要。希望这有助于某人,某个时候
这回答了你的问题吗<代码>新文件输出流(“stack.txt”)代码>替换为
文件文件=新文件(根,“stack.txt”);新文件输出流(文件)代码>@Joachim Sauer我在那里没有找到答案。有趣的东西,但不是一种文件技术,我可能会用它来打开一系列字符串进行写和读:(blackapps)我不知道如何按照你的建议进行替换:(我需要使用readUTF和writeUTF,这需要ObjectInputStream和ObjectOutputStream。我用我的新方法编辑了这篇文章。似乎writeUTF/readUTF是唯一一对将字符串写入文件然后将其读回的字符串。它们是java.io.ObjectOutputStream的一部分。我需要找到一种在不崩溃的情况下打开/关闭文件的方法。
root = new File(getExternalFilesDir(null), "/HTMLSpyII/");
if (!root.exists()) {
if (!root.mkdirs()) {
runTimeAlert("File path does not exist or\n" +
"Unable to create path \n" + root.toString());
}
}
try {
DataOutputStream dos = new DataOutputStream(
new FileOutputStream("stack.txt")); // program fails here
for (String item : stack)
dos.writeUTF(stack.pop());
dos.close();
sb.append("The Stack is saved.\n");
} catch (IOException e) {
sb.append(e.toString());
}
displayText(sb.toString());
File stackRoot = new File(getExternalFilesDir(null), "/AppName/stack.dat");
FileOutputStream fos = new FileOutputStream(stackRoot);
ObjectOutputStream oos = new ObjectOutputStream(fos);
for (String item : stack) oos.writeObject(item);
oos.close();
File stackRoot = new File(getExternalFilesDir(null), "/AppName/stack.dat");
FileInputStream fis = new FileInputStream(stackRoot);
ObjectInputStream ois = new ObjectInputStream(fis);
while (true) stack.addLast((String) ois.readObject());