用java实现删除目录
2021-01-02 13:28
标签:system let new ati files else ring file string 用java实现删除目录 用java实现删除目录 标签:system let new ati files else ring file string 原文地址:https://www.cnblogs.com/wzihan/p/12994367.html public static void main(String[] args) {
try {
String strFolder = "D:\\aa";
deleteFile(new File(strFolder));
System.out.println("Delete Successful!");
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("Delete Fail!");
}
}
public static void deleteFile(File file) {
if (file == null || !file.exists()) {
return;
}
File[] files = file.listFiles();
for (File f : files) {
if (f.isDirectory()) {
deleteFile(f);
} else {
f.delete();
}
}
file.delete();
}
上一篇:[Java]多线程
下一篇:采用位图求数组或者字符串的子序列