随笔-145  评论-173  文章-70  trackbacks-0
 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 阅读(8209) 评论(2)  编辑 收藏 引用 所属分类: Java

评论:
# re: Java递归实现遍历文件目录(所有文件夹和子文件) 2011-09-04 11:27 | kingwolfofsky
o(∩_∩)o 哈哈,以前我也写过
一起晒一下
http://www.cnblogs.com/kingwolfofsky/archive/2010/03/29/2093945.html  回复  更多评论
  
# re: Java递归实现遍历文件目录(所有文件夹和子文件) 2011-09-04 21:50 | 刘畅
@kingwolfofsky
膜拜大神!  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理