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);
}
}
}
}