Android IOException错误信息解释

Android IOException error message interpretation

我不断收到 IOException,但我不明白这是什么意思。

代码(伪):

File file = new File("/filepath/");
fos = new FileOutputStream(file);
String str =  String.format("0");
fos.write(str.getBytes());
fos.close();

错误:

W/System.err( 1794): java.io.IOException: write failed: EBUSY (Device or resource busy)
W/System.err( 1794):  at libcore.io.IoBridge.write(IoBridge.java:452)
W/System.err( 1794):  at java.io.FileOutputStream.write(FileOutputStream.java:187)
W/System.err( 1794):  at java.io.OutputStream.write(OutputStream.java:82)

"write failed: EBUSY (Device or resource busy)" 部分是什么意思?

如果您在线搜索,您会发现有几个进程使用了​​该文件,或者您删除了文件但没有删除引用。您可以在尝试写入文件或对文件执行某些操作之前尝试搜索文件是否存在。 我的解决方案是在对文件执行某些操作之前搜索文件是否存在,如果存在,则删除并创建新文件或类似的东西。
open failed: EBUSY (Device or resource busy)

听起来您要打开的文件已在使用中。 SO上有一些相关的问题。

open failed: EBUSY (Device or resource busy)

可能由于调试和重新启动你的应用程序,该文件仍在使用中。