/**
* 使用递归算法
*/
public class FileSearch {
public void search(File file, String extendName) {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (File f : files) {
search(f, extendName);
}
} else {
boolean yes = file.getPath().endsWith(extendName);
if (yes) {
System.out.println(file.getPath());
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
File file = new File("C:/bea");
FileSearch fs = new FileSearch();
fs.search(file, ".java");
}
}