public class Main
{
public static void showDir(File file, FilenameFilter filter)
{
File[] files = file.listFiles(filter);
System.out.println(file.getAbsolutePath());
for(File f : files)
{
if(f.isDirectory())
showDir(f,filter);
else
System.out.println(f.getAbsolutePath());
}
}
public static void main(String[] args)
{
File f = new File("D:\\Dev-Cpp");
showDir(f, new FilenameFilter()
{//内部类
public boolean accept(File dir, String name)
{
File f = new File(name);
if(f.isDirectory())
{
return true;
}
else
return f.getName().endsWith(".txt");
}
});
}
}
内部类该怎么写?(加粗部分代码不对)
或者更好的方法?
|
|