版权声明:士,不可以不弘毅,任重而道远 https://blog.csdn.net/superbeyone/article/details/83783806
Java递归删除指定文件夹下所有文件
工具类封装
public class FileUtils{
public static boolean delAllFile(String path) {
return delAllFile(new File(path));
}
public static boolean delAllFile(File path) {
boolean flag = false;
if (!path.exists()) {
return flag;
}
if (!path.isDirectory()) {
return flag;
}
String[] fileList = path.list();
File file;
for (int i = 0; i < fileList.length; i++) {
file = new File(path + File.separator + fileList[i]);
if (file.isFile()) {
file.delete();
}
if (file.isDirectory()) {
delAllFile(file);
file.delete();
flag = true;
}
}
return flag;
}
}