1 package TimeClass01;
2 /**
3 * 树状结构目录显示
4 */
5 import java.io.File;
6
7 public class Filestudy {
8
9 public static void PrintFile(File file, int level) {
10 for (int i = 0; i < level; i++) {
11 System.out.print("----");
12 }
13 System.out.println(file.getName());
14 if (file.isDirectory()) {
15 File[] files = file.listFiles();
16 for (File temp : files) {
17 PrintFile(temp, level + 1);
18 }
19 }
20 }
21
22 public static void main(String[] args) {
23 File f = new File("e:/java");
24 PrintFile(f, 0);
25
26 }
27 }