0
点赞
收藏
分享

微信扫一扫

JAVA 删除指定目录下指定文件类型的所有文件

程序员知识圈 2022-08-18 阅读 145

public class DelFile {
public static void main(String[] args) {
File file = new File("C:\\DETECTX_OUTPUT");
delete(file);
}

private static void delete(File f) {
File[] fi = f.listFiles();
for (File file : fi) {
if (file.isDirectory()) {
delete(file);
} else if (file.getName().substring(file.getName().lastIndexOf(".") + 1).equals("html")) {
System.out.println("成功删除" + file.getName());
file.delete();

}
}
}
}

 



举报

相关推荐

0 条评论