java遍历文件夹并判断文件夹中的文件后缀是否满足条件,满足就删除此文件

如题所述

new File(file).delete();
endWith判断扩展名,最好是".html",前面加上点追问

private static void deleteEndFile() {
File f = new File("e:/c");
String[] ff = f.list();
for (String file: ff) {
if(file.endsWith("html")){
new File(file).delete();
}
}
}

不行!!!

追答

抱歉,没运行代码,以为f.list()是获得路径。

String path="e:/c";
        File f = new File(path);
        String[] ff = f.list();
        for (String file : ff) {
            if (file.endsWith("html")) {
                System.out.println(file);
                new File(path+"/"+file).delete();
            }
        }

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答