我一直得到一个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)
写失败:EBUSY (Device or resource busy)部分是什么意思?
听起来您要打开的文件已在使用中。这里有一些与SO相关的问题。
open failed: EBUSY (Device or resource busy)
可能由于调试和重新启动应用程序,该文件仍在使用中。
如果您在线搜索它,您会发现要么有几个进程使用该文件,要么您删除了该文件,但没有删除引用。在尝试写文件或对文件进行操作之前,您可以尝试搜索该文件的存在。我的解决方案是在对它做一些事情之前搜索文件的存在,如果它存在,删除并创建新的或类似的东西。
open failed: EBUSY (Device or resource busy)