随笔-71  评论-5  文章-0  trackbacks-0
 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 藤本蔷薇 阅读(163) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: