1.用FileFilter
File[] fs = dir.listFiles(new FileFilter() {
public boolean accept(File pathname) {
String tmp = pathname.getName().toLowerCase();
if (tmp.endsWith("_serverddconfig.xml")) {
//if(tmp.endsWith(".xml")){
return true;
}
return false;
}
});
2.用FileNameFilter
假设是在Main函数中使用
public static void main(final String[] args){
File[] fs = dir.listFiles(new FileNameFilter(){
public boolean accept(File dir, String fileName){
String f = new File(fileName).getName();
return f.indexOf(args[0]!=-1;
}
});
}