使用indexOf()从文件夹中搜索文件

时间:2013-06-21 06:54:16

标签: java

import java.io.*;

class FindFile {
   public static void main(String[] args) {
      File dir = new File("D:/Abhishek/src/com/siemens/med/hs/sf/payer/billing/claiminterface");
      FilenameFilter filter = new FilenameFilter() {
         public boolean accept
         (File dir, String name) {
            return name.indexOf("Claim");
             }
      };
      String[] children = dir.list(filter);
      if (children == null) {
         System.out.println("Either dir does not exist or is not a directory");
      } 
      else {
         for (int i=0; i< children.length; i++) {
            String filename = children[i];
            System.out.println(filename);
         }
      } 
   }
}

1 个答案:

答案 0 :(得分:1)

我认为你的意思更像是

return name.toLowerCase().indexOf("claim") > -1;

FileFilter班级......