File access (delete / open) in Android 3.0 and higher

I am having a problem with the HoneyComb file system. First, I clear the files in the directory. And after deleting, if I do any operations again on that directory, the error message java.io.IOException is thrown: device or resource busy . The exception has never been in OS 2.2 or 2.3.

The code I am using to delete files in a directory is

public static void emptyTheDirectory(File file){

if(file.exists()){
    if(file.isDirectory()){                         //dir
        File childrenFiles[] = file.listFiles();
        if(childrenFiles.length != 0){
            for(File childFile : childrenFiles){

                emptyTheDirectory(childFile,isLoggingOut);      //delete subFodler/file
            }//end for 
        }
    }

    try{
        //If the file is folder, by now all files in folders are deleted.

        boolean bool = file.delete();               //delete file

    }catch (Exception e) {
        e.printStackTrace();
    }
}

      

}

Am I doing something wrong? Is there a safer way to access the file system in android?

Please suggest.

Update

After applying the above code to the root folder, I noticed that the root folder created by the application was changed to a file with the same name, and the installed file managers would not be able to delete the file either.

Regards,
Sha.

+3
android android-file


source to share


No one has answered this question yet

Check out similar questions:

964
Download file from Android and show progress in ProgressDialog
862
What are the "tools: context" in android layout files?
703
How to install APK file in Android emulator?
620
How to define circle shape in rendered android xml file?
617
How to check Internet access on Android? InetAddress never runs out
568
What permission do I need to access the Internet from an Android app?
526
How to open Google Play Store directly from Android app?
470
How can I access my localhost from my android device?
7
Android mkdirs () creates a null byte file instead of a folder
0
Android: copying .jpg image after deleting same gives error



All Articles
Loading...
X
Show
Funny
Dev
Pics