代码:
import java.io.File;
public class FileShow {
static class Test12 {
public static void main(String[] args) {
File f = new File("C:\Users\19821\Desktop\面试");
for(File temp : f.listFiles()) {
if(temp.isFile()) {
System.out.println(temp.getName());//打印文件的名字
}
}
}
}
static class Test12 {//文件夹的继续展开
public static void main(String[] args) {
showDirectory(new File("C:\Users\19821\Desktop\面试"));
}
public static void showDirectory(File f) {
_walkDirectory(f, 0);
}
private static void _walkDirectory(File f, int level) {
if(f.isDirectory()) {//是文件目录
for(File temp : f.listFiles()) {
_walkDirectory(temp, level + 1);
}
}
else {//是文件
for(int i = 0; i < level - 1; i++) {
System.out.print(" ");
}
System.out.println(f.getName());
}
}
}
}