open failed: EBUSY (Device or resource busy)

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.


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!