open failed: EBUSY (Device or resource busy)

非 Y 不嫁゛ 提交于 2019-11-29 23:42:39
Informatic0re

I have a big Answer!! The Problem comes from the Android System or/and the FAT32 system. I can not explain how the system gets the error, it has something to do with deleting files and the FAT32 System.

But the solution is really easy: Before you delete a Directory or File: rename it!

Code to rename:

final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
file.renameTo(to);
to.delete();

That's it, if you rename the folder or file before you delete it, there is no chance for the system to try to open an existing file again or an open file which you want to save again (or something like this).

This issue may be cause by

  • two or more process reference the same file

  • file was deleted,but the reference not be killed

However,deleted it,only one reference was killed,or one or more process reference this file also

you can step by step:

before you delete the file you should

  • adb shell lsof | grep "com.xxxxxx.android"

The file you have been opened,and which process reference the file which you opened. also,this command ,show us the process id

than,

  • adb shell ls -al /proc/%d/fd

Surprise waiting for you, O(∩_∩)O

good luck!

It seems to be a lingering filesystem lock. I fixed it without touching my code, I think it was by unplugging my USB cable and re-plugging it in.

Was getting the exact same error, tried unplugging, restarting eclipse etc but nothing was working. Finally had to reboot phone and all fell back into place ;)

Thanks for putting me on the right route !!

I noticed this error in Sony Xperia when file in the directory not closed after writing some content in to it and I am trying to access(modify/delete) the directory.

Make sure to close the file properly. Make sure no program is accessing your files. Then you wont come across this error.

If you are unsure that any program might be accessing your directory, be sure to delete(/close) all the files in the directory before deleting the directory.

adb reboot is one option to close opened files. But that is not a good option to do so.

I understand that this is an old issue, and was originally reported specific to a XOOM, but if the OP had an open FileOutputStream that was not properly closed, i.e. via a Finally block, then that is likely what is causing the resource to be held when attempting to reference it later... even if the physical file was actually deleted.

farrellw

The message rm: could not remove directory (code EBUSY), means that some app or process is using the directory.

For me, this usually means AndroidStudio, Webstorm, or another IDE is open. If you have an IDE open, closing it can free up the process to remove the folder. After closing, just run the removal again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!