Delete folder from internal storage in android?

前端 未结 4 1114
再見小時候
再見小時候 2021-02-02 10:45

How to delete folder(contain some folder and file) from internal storage? Folder have some below tree.

folder
|_________  C2 (folder)
             |________1 (fo         


        
4条回答
  •  遥遥无期
    2021-02-02 11:24

    Let me tell you first thing you cannot delete the Rootfolder because it is a system folder. As you delete it manually on phone it will delete the contents of that folder, but not the Root folder. You can delete its contents by using the method below:

    private void DeleteRecursive(File fileOrDirectory) {
        if (fileOrDirectory.isDirectory())
            for (File child : fileOrDirectory.listFiles())
            {
                child.delete();
                DeleteRecursive(child);
            }
    
        fileOrDirectory.delete();
    }
    

提交回复
热议问题