java显示windows文件夹下的所有exe文件

import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class DirList {
public static void main(String[] args) {
 File path=new File("C:Windows");
 String []list;
 list=path.list(new DirFilter("exe"));
 //list=paht.list();
 Arrays.sort(list,String.CASE_INSENSITIVE_ORDER);
 for(String dirItem:list)
 System.out.println(dirItem);
 }

}
class DirFilter implements FilenameFilter{
 private Pattern pattern;
 DirFilter(String regex){
 pattern=Pattern.compile(regex);
 }
 public boolean accept(File dir,String name){
  Matcher m=pattern.matcher(name);
  return m.find();
 }
}

by 雪洁 2011-06-07 16:12:23 2795 views
我来说几句

相关文章