1 import java.io.*;
 2 
 3 public class Test {
 4     public static void main(String args[]) {
 5         File file = new File("E:/B");
 6         System.out.println(file.getName());
 7         tree(file,1);
 8     }
 9     
10     private static void tree(File f, int level) {
11         String preStr = "";
12         
13         for(int i = 0; i < level; i++) {
14             preStr += "    ";
15         }
16         
17         File[] childFile = f.listFiles();
18         for(int i = 0; i < childFile.length; i++) {
19             System.out.println(preStr + childFile[i].getName());
20             if(childFile[i].isDirectory()) {
21                 tree(childFile[i],level++);
22                 
23             }
24         }
25         
26     }
27 }

 

posted on 2018-08-27 15:48  蕾拉  阅读(375)  评论(0)    收藏  举报