1

11111111111

 1     /**
 2      * @TODO 查询指定路径下的文件以什么结尾的数据
 3      * @param path    指定路径
 4      * @param pattern    以什么结尾
 5      * @return
 6      */
 7     public static List<Object> getFile(String filePath,String pattern,List<Object> list){
 8         list = new ArrayList<Object>();
 9         if(filePath!=null && !"".equals(filePath)){
10             File file = new File(filePath);
11             if(file.isDirectory()){
12                 String[] files = file.list();
13                 for(String f:files){
14                     File readFile = new File(filePath+File.separator+f);
15                     if(readFile.isDirectory()){
16                         List<Object> list2 = getFile(filePath+File.separator+f,pattern,list);
17                         list.addAll(list2);
18                     }else{
19                         if(readFile.getName().indexOf(pattern)!=-1){
20                             list.add(readFile.getPath());
21                         }
22                     }
23                 }
24             }else{
25                 if(file.getName().indexOf(pattern)!=-1){
26                     list.add(file.getPath());
27                 }
28                 
29             }
30         }
31         return list;
32     }
View Code

 

posted on 2019-07-12 10:18  Terlong  阅读(80)  评论(0)    收藏  举报

导航