-------------------------------------对于有多层内容的文件夹来说,要彻底删除的话,就需要编写代码进行迭代操作--------------------------------------

/**

* 迭代删除文件夹

* @param dirPath 文件夹路径

*/

public static void deleteDir(String dirPath){

  File file = new File(dirPath);// 读取

  if(file.isFile()){ // 判断是否是文件夹

    file.delete();// 删除

  }else{

    File[] files = file.listFiles(); // 获取文件

    if(files == null){

      file.delete();// 删除

    }else{

      for (int i = 0; i < files.length; i++){// 循环

         deleteDir(files[i].getAbsolutePath());

      }

      file.delete();// 删除

    }

  }

}

相关文章:

  • 2022-12-23
  • 2021-08-09
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-11
  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案