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(); } }