如题,之前看到有人问这个问题,回答的人的解释import java.io.*;public class testFile {    public static void main(String[] arg) {
        File dir = new File("D:\\a\\");
               
        FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
                String s = name.substring(0, name.lastIndexOf("."));
           System.out.print(s+"++  "  ); ****这里的s已经是我想要的内容
               return s.equals("MyClass");
            }
        };
        String[] children = dir.list(filter);****到这里就过不去了。
     
            for (int i = 0; i < children.length; i++) {
                //   Get   filename   of   file   or   directory
                String filename = children[i];
               System.out.print(filename+"++  "  );得到的是全名(带后缀的)
           
        }     }}

解决方案 »

  1.   

    我写了这个,测过好像可以. 
    File fdir = new File("d:\\");
        //フォルダにあるファイルのみ処理の対象になる
        File[] fList = fdir.listFiles(new FileFilter() {      
          public boolean accept(File arg0) {
            if (arg0.isFile()) {
              //String s = "";
              if (arg0.getPath().lastIndexOf(".") <= 0) {
                //s = arg0.getPath().substring(0);
                return true;
              } else {
                //s = arg0.getPath().substring(0, arg0.getPath().lastIndexOf("."));
                return false;
              }
            }
            return false;
          }      
        }); 
        
        
        for (int i = 0;  i < fList.length; i++) {
          System.out.println(fList[i].getName());
          System.out.println(fList[i].getPath());
        }