3 import java.io.File;
4
5 public class ListAllPath {
6 public void print(File mFile, int mlevel){
7 for(int i = 0; i < mlevel; i++){
8 System.out.print("\t");
9 }
10 if (mFile.isDirectory()){
11 System.out.println("<" + getPath(mFile) + ">");
12 String[] str = mFile.list();
13 for (int i = 0; i < str.length; i++){
14 print(new File(mFile.getPath() + "\\" + str[i]) , mlevel + 1);
15 }
16 }else{
17 System.out.println(getPath(mFile));
18 }
19 }
20
21 public String getPath(File mFile){
22 String fullPath = mFile.getPath();
23 String[] str = fullPath.split("\\\\");
24 return str[str.length - 1];
25 }
26
27 }
1 import java.io.File;
2
3 public class Demo {
4 public static void main(String[] args){
5 ListAllPath demoTest = new ListAllPath();
6 File rootFile = new File("E:\\job");
7 demoTest.print(rootFile, 0);
8 }
9 }
10
posted on 2011-08-21 01:44
deercoder 阅读(8273)
评论(2) 编辑 收藏 引用 所属分类:
Java