How to delete all files and folders in one folder on Android

前端 未结 12 1217
广开言路
广开言路 2021-01-30 17:52

I use this code to delete all files:

File root = new File(\"root path\");
File[] Files = root.listFiles();
if(Files != null) {
    int j;
    for(j = 0; j < F         


        
12条回答
  •  萌比男神i
    2021-01-30 17:54

    File file = new File("C:\\A\\B");        
        String[] myFiles;      
    
         myFiles = file.list();  
         for (int i=0; i

    You can write method like this way :Deletes all files and subdirectories under dir.Returns true if all deletions were successful.If a deletion fails, the method stops attempting to delete and returns false.

    public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (int i=0; i

提交回复
热议问题