Java实现的文件过滤代码分享(按后辍过滤)

好久没有写代码了,也好久没有更新我的博客了,昨晚写了这个过滤文件名的程序,遂发之~

 /*name:FileNameFilter
 *author : Runzhen Wang 
 *date:2009/11/04
 */
 
 import java.util.*;
 import java.io.*;
 import java.lang.*;
 
 class FileNameFilter{
   public void filter(String strPath,String fname){
     File f=new File(strPath);
     String s=new String();
     if(f.isDirectory()){
       File[] fList =f.listFiles();
       for(int i=0;i<fList.length;i++){
          if(fList[i].isFile()&&fList[i].getName().endsWith(fname)){
            System.out.println(fList[i].getName());
          }
       }
     }
 
   }
 }
 
 public class FileNameFilterDemo{
   public static void main(String[] args){
     FileNameFilter fnf=new FileNameFilter();
     Scanner kb=new Scanner(System.in);
     String str1=new String();
     String str2=new String();
     System.out.print(“输入文件目录:”);
     str1=kb.next();
     System.out.print(“输入过滤后缀名:”);
     str2=kb.next();
     fnf.filter(str1,str2);
   }
 }