【发布时间】:2017-10-17 13:53:51
【问题描述】:
我尝试在没有文件的目录中删除文件,该路径在我的数组中
public static boolean deleteDir(File dir, List<String> exclusionList) throws IOException {
if (exclusionList != null && exclusionList.contains(dir.getCanonicalPath())) { // skip file
System.out.println("Skipped: " + dir.getCanonicalPath());
return true;
}
System.out.println("Deleting: " + dir.getCanonicalPath());
if (dir.isDirectory()) {
File[] children = dir.listFiles();
boolean success = true;
for (File element : children) {
if (!deleteDir(element, exclusionList)) {
success = false;
}
}
return success;
}
return dir.delete();
}
这是我的删除功能,可以很好地删除 .txt .yml 等文件,但是当它必须删除文件夹(文件夹内容删除 perflecty)但文件夹存在时,我有很多空文件夹;/
【问题讨论】:
标签: java