import java.io.*;
/*
* 递归删除文件夹内与给定的文件名不符的文件和所有的文件夹
*/
public class Test3 {
public static void checkName(String[] filelist) {
File file = new File("D:\\temp");
File[] files = file.listFiles();
boolean flag = true;
for (int i = 0; i < files.length; i++) {
for (int j = 0; j < filelist.length; j++) {
if (files[i].isFile()) {
if (files[i].getName().equals(filelist[j])) {
flag = false;
break;
} else {
flag = true;
}
} else if (files[i].isDirectory()) {
del(files[i]);
}
}
if (flag) {
files[i].delete();
}
}
}
private static void del(File f) {
if (f.isFile()) {
f.delete();
} else if (f.isDirectory()) {
String[] files = f.list();
for (int i = 0; i < files.length; i++)
del(new java.io.File(f.getAbsolutePath() + "\\" + files[i]));
f.delete();
}
}