今天遇到的面试题,做个总结,直接上代码:
public static void read(String path) {
File file = new File(path);
if (file.isDirectory()) {
File[] files = file.listFiles();
for (File f : files) {
if (file.isDirectory()) {
read(f.getPath());
} else {
System.out.println(f.getName());
}
}
} else {
System.out.println(file.getName());
}
}
主要考察的是对io流的应用,记着记着,加强练习。