When you delete a file, and then re-download the same name file, save to SDcard error, some phones appear
caused By:libcore. io. Errnoexception: Open failed:ebusy (Deviceor resource busy)
At Libcore. Io. Posix. Open(Native Method)
At Libcore. Io. Blockguardos. Open(Blockguardos. Java:+)
At Java. io. File. createnewfile(file. java:941)
This problem in Xiaomi 3, Huawei series mobile phones appear more likely.
The file creation failed because the file was deleted and still occupied by other processes.
Enter the ADB shell to view the process that occupies the file through the lsof command.
It is said that this is an Android file system bug, it is recommended to delete the file before you rename the file:
To remove a file security method:
private void DeleteFile (file file) {
if (File.isfile ()) {
deletefilesafely (file);
Return
}
if (File.isdirectory ()) {
file[] Childfiles = File.listfiles ();
if (Childfiles = = NULL | | childfiles.length = = 0) {
deletefilesafely (file);
Return
}
for (int i = 0; i < childfiles.length; i++) {
DeleteFile (Childfiles[i]);
}
deletefilesafely (file);
}
}
/**
* Safely delete files.
* @param file
* @return
*/
public static Boolean deletefilesafely (file file) {
if (file! = null) {
String Tmppath = file.getparent () + File.separator + system.currenttimemillis ();
File TMP = new file (Tmppath);
File.renameto (TMP);
return Tmp.delete ();
}
return false;
}
Error in Android Delete file