public static boolean forbidFormat(String threeLetter){
List<String> fileFormat = new ArrayList<String>();
fileFormat.add("pdf"); //删除什么文件可多个
if(fileFormat.contains(threeLetter)){
return true;
}else{
return false;
}
}
File file = new File("E:/upload/protocol/");
boolean isDirectory = file.isDirectory();
if (isDirectory) {
String[] files = file.list();
for (String path : files) {
String afterPointLetter = path.substring(path.lastIndexOf(".") + 1, path.length());
if (forbidFormat(afterPointLetter)) {
System.out.println(DOWN_ADDRESS + path);
File deleteFile = new File(DOWN_ADDRESS + path);
if (deleteFile.exists()) {
deleteFile.delete();
}
}
}
log.info("---------删除成功");
} else {
if (file.isFile()) {
file.delete();
}
}