Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从SD卡中删除文件夹_Java_Android_File - Fatal编程技术网

Java 从SD卡中删除文件夹

Java 从SD卡中删除文件夹,java,android,file,Java,Android,File,我的SD卡里有一些文件夹。我想删除关闭活动(即onDestroy()回调)中的文件夹。例如:我有folderA、folderB和FolderC。我可以删除folderA和FolderB。这些文件夹包含文件(.zip、.pdf等),但folderC我无法删除它包含文件夹、子文件夹和文件。下面是我的代码 deletUnZipedFiles(File file){ file = new File(MainActivity.root_sd,"/folderC"); if (file.isDirec

我的SD卡里有一些文件夹。我想删除关闭活动(即onDestroy()回调)中的文件夹。例如:我有folderA、folderB和FolderC。我可以删除folderA和FolderB。这些文件夹包含文件(.zip、.pdf等),但folderC我无法删除它包含文件夹、子文件夹和文件。下面是我的代码

deletUnZipedFiles(File file){
file = new File(MainActivity.root_sd,"/folderC");   
if (file.isDirectory()) {
   String[] children = file.list();
    for (int i=0; i<children.length; i++) {
    boolean success = deletUnZipedFiles(new File(file, children[i]));
    System.out.println("status of unziped delet"+success);
    if (!success) {
      return false;
     }
    }
  }
  // The directory is now empty so delete it
 //return file.delete();
}
deletUnZipedFiles(文件){
file=新文件(MainActivity.root_sd,“/folderC”);
if(file.isDirectory()){
String[]children=file.list();

对于(int i=0;i您可以使用此功能删除文件夹。您需要传递文件对象,如:

File file = new File("C:\\A\\B"); 
DeleteRecursive(file);

void DeleteRecursive(File fileOrDirectory) {

 if (fileOrDirectory.isDirectory())
    for (File child : fileOrDirectory.listFiles())
        DeleteRecursive(child);

    fileOrDirectory.delete();

    }
您在android清单文件中添加了权限了吗?为什么要对此-->//return file.delete()进行注释;