public static boolean delFilesByPath(String path,String str){
//參數說明---------path:要刪除的文件的文件夾的路徑---------str:要匹配的字符串的頭
boolean b=false;
File file = new File(path);
File[] tempFile = file.listFiles();
for(int i = 0; i < tempFile.length; i++){
if(tempFile[i].getName().startsWith(str)||tempFile[i].getName().endsWith(str)){
tempFile[i].delete();
b=true;
}
}
return b;
}
public static void main(String[] args) {
String path="F:/Installed---success---go/apache/webapps/images";
String str="181";
if(delFilesByPath(path,str)){
System.out.println(path+"中包含"+str+"的文件已經全部刪除成功!");
}else{
System.out.println(path+"中包含"+str+"的文件已經刪除失敗或該文件夾下不存在這類文件!");
}
}
posted on 2015-03-06 10:09
藤本薔薇 閱讀(173)
評論(0) 編輯 收藏