import java.io.*;public class TestFile{     public static void main(String[] args){
         String tmp;
         File pathname=new File(args[0]);
         FileFilter fileFilter=new FileFilter(){
              public boolean accept(File pathname){
                   String tmp=pathname.getName().toLowerCase();
                   if(tmp.endsWith(".java"))
                       return true;
                   
                   return false;
              }
         }
         File[] filelist=pathname.listFiles(fileFilter);
         for(int i;i<fileList.length;i++){
                System.out.println(filelist[i]);
         }
     }
}

解决方案 »

  1.   

    public static void main(String[] args){
             String tmp;
             File pathname=new File(args[0]);
             FileFilter fileFilter=new FileFilter(){
                  public boolean accept(File pathname){
                       String tmp=pathname.getName().toLowerCase();
                       if(tmp.endsWith(".java"))
                           return true;
                       
                       return false;
                  }
             };
             File[] filelist=pathname.listFiles(fileFilter);
             for(int i=0;i<filelist.length;i++){
                    System.out.println(filelist[i]);
             }
         }
      

  2.   

    import java.io.*;public class TestFile{     public static void main(String[] args){
             String tmp;
             File pathname=new File(args[0]);
             FileFilter fileFilter=new FileFilter(){
                  public boolean accept(File pathname){
                       String tmp=pathname.getName().toLowerCase();
                       if(tmp.endsWith(".java"))
                           return true;
                       
                       return false;
                  }
             };//少了一个分号!
             File[] filelist=pathname.listFiles(fileFilter);
             for(int i;i<fileList.length;i++){
                    System.out.println(filelist[i]);
             }
         }
    }
      

  3.   

    我就是打算列出某个目录下的java文件。希望大侠帮帮我。还有就是FileFilter和FilenameFilter有什么不同?