java递归全盘便利出现空指针异常,是因为没有判断空文件夹吗?
package mycode;
import java.io.File;
public class Filejpg {
public static void main(String[] args) {
File fl = new File("E:\\");
System.out.println(fl.isDirectory());
getNum(fl);
System.out.println(count);
}
static int count = 0;
private static void getNum(File fl) {
File[] fls = fl.listFiles();
for (File fi : fls) {
System.out.println(fi.getName());
if(fi.isFile()&&fi.getName().endsWith(".jpg")){
count++;
}else if(fi.isDirectory()){
getNum(fi);
}
}
}
}
慕婉清6462132
相关分类