java FileFilter的使用

package filterdemo;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;

public class FilterDemo {
    
    public static void main(String args[]) throws IOException{
        File f = new File("D:\\Temp");
        
        FileFilter ff = new FileFilter() {
            
            @Override
            public boolean accept(File pathname) {
                // TODO Auto-generated method stub
                String s = pathname.getName().toLowerCase();
                
                if(s.endsWith(".txt")){
                    return true;
                }
                
                return false;
            }
        };
        
        File[] flist = f.listFiles(ff);

        if(flist == null){
            System.out.println("the flist is null");
            return;
        }
        
        for(File fs: flist){
            System.out.println(fs);
        }
        
    }

}
posted @ 2012-10-23 09:49  hnrainll  阅读(6848)  评论(0编辑  收藏  举报