import java.io.File;
public class FileTree {
public static void main(String[] args) {
File f=new File("d:/BaiduYunDownload");
printTree(f,0);
}
public static void printTree(File f,int level){
for(int i=0;i<level;i++){
System.out.print("-");
}
System.out.println(f.getName());
if(f.isDirectory()){
File files[]=f.listFiles();//获取当前目录下所有文件和文件夹
for(File temp:files)
printTree(temp,level+1);//递归调用
}else return;//不是目录就返回调用处
}
}