代码如下
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class DirLists {
class DirFilter implements FilenameFilter{
private Pattern pattern;
public DirFilter(String regex){
pattern = Pattern.compile(regex);
}
public boolean accept(File dir,String name){
return pattern.matcher(name).matches();
}
}
public static void main(String [] arg){
String [] li =( new File("c:\\Users\\xiaohe\\workspace\\aff\\src")).list( new DirFilter("D.*\\.java"));
}
}
问题在这里:
String [] li =( new File("c:\\Users\\xiaohe\\workspace\\aff\\src")).list( new DirFilter("D.*\\.java"));
------解决方案--------------------
public static void main(String [] arg){
DirLists dirList = new DirLists();
String [] li =( new File("c:\\Users\\xiaohe\\workspace\\aff\\src")).list( dirList.new DirFilter("D.*\\.java"));
}
这个是个内部类,这样调用