定義函數
/**
* 刪除指定文件夾下的所有文件
* @param path
* @return
*/
public static boolean delAllFile(String path) {
boolean flag = false;
File file = new File(path);
if (!file.exists()) {
System.out.println("111");
return flag;
}
if (!file.isDirectory()) {
System.out.println("222");
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++) {
if (path.endsWith(File.separator)) {
System.out.println("225"+temp);
temp = new File(path + tempList[i]);
} else {
System.out.println("2244"+temp);
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile()) {
System.out.println("111"+temp);
System.out.println("666"+tempList);
temp.delete();
}
}
return flag;
}
調用
delAllFile("D:/log/video");