求所有文件下的.txt文件的个数
/**
* 求所有文件下的.txt文件的个数
* @param f
* @return
*/
private int countTxt(File f) {
if(f == null || !f.exists()) return 0;
File[] list = f.listFiles();
int count = 0;
for (File item : list) {
if(item.isFile()) {
String name = item.getName();
int index = name.lastIndexOf(".");
name = name.substring(index, name.length());
if(name.equals(".txt")) {
count++;
}
} else {
count +=countTxt(item);
}
}
return count;
}