Error in Android Delete file

Source: Internet
Author: User

When deleting a file and downloading the same name again, the error occurs when saving to sdcard, and 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 issue is in Xiaomi 3. Huawei series mobile phones have a large probability of appearing.
The reason for file creation failure is. The file is still being consumed by other processes after it is deleted.
Enter the ADB shell. View the process that occupies the file by using 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.