Java删除文件夹下所有文件
public static boolean deleteAllFile(String path, boolean isIncludeRoot) {
if(StringUtils.isBlank(path)) {
return false;
}
File file = new File(path);
if (!file.exists()) {
return false;
}
if(file.isFile()) {
return file.delete();
}
File[] fileList = file.listFiles();
boolean res = true;
for (File f : fileList) {
if(f.isFile()) {
res = res && f.delete();
} else if(f.isDirectory()) {
res = res && deleteAllFile(f.getAbsolutePath(), true);
}
}
if(isIncludeRoot) {
res = res && file.delete();
}
return res;
}