JAVA学习笔记-File列出指定目录的树状结构

package TestFileTree;

import java.io.File;

public class TestFileTree {
  public static void main(String[] args){
    File file = new File("C:/Users/iwang/Desktop/Test");
    printfile(file,0);
}

public static void printfile(File file,int level){
  for(int i=0;i<level;i++){
    System.out.print("-");
  }
System.out.println(file.getName());
  if(file.isDirectory()){
    File[] filelist = file.listFiles();
    for(File temp : filelist){
      printfile(temp,level+1);
    }
  }
}
}

posted @ 2016-11-14 17:04  iamAnonymous  阅读(865)  评论(0编辑  收藏  举报