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


source to share





All Articles