1
/*
2
* 編寫一個程序,
3
* 在命令行中以樹狀結構
4
* 展現特定的文件夾機器子文件(夾)
5
*/
6
7
import java.io.*;
8
9
public class FileList {
10
11
public static void main(String[] args){
12
tree(new File("d:/Recycler/Legend_Wind"),0);
13
}
14
15
private static void tree(File f,int level){
16
String preStr="";
17
for (int n = 0;n<level;n++) preStr +="\t\t";
18
19
File[] sub=f.listFiles();
20
for(int i=0;i<sub.length;i++){
21
if(sub[i].isDirectory()){tree(sub[i],level+1);}
22
System.out.println(preStr+sub[i].getName());
23
}
24
System.out.println();
25
}
26
}
27

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27
