[Java] 纯文本查看 复制代码 import java.io.File;
public class Listavi {
public static void main(String[] args) {
File f = new File("D:\\");
getAvis(f);
}
public static void getAvis(File file) {
File[] files = file.listFiles();
if (files != null) {
for (File tempfile : files) {
if (tempfile != null) {
if (tempfile.isFile() && tempfile.getName().endsWith(".avi")) {
System.out.println(tempfile);
} else {
getAvis(tempfile);
}
}
}
}
}
}
官方对listFiles()方法的解释:
Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.
If this abstract pathname does not denote a directory, then this method returns null.
所以要加个为null的判断! |