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 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.isDirectory()){                         //dir
        File childrenFiles[] = file.listFiles();
        if(childrenFiles.length != 0){
            for(File childFile : childrenFiles){

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

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

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

    }catch (Exception e) {



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

Please suggest.


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.



source to share

All Articles