供初学者学习
转贴请不要删除作者信息 :)
import java.io.*;
import java.io.File;
class FileTree{
public static void main(String[] arg) {
if (arg.length==0){
System.out.println("请加上路径参数如: c:windows");
}
try {
File getfile = new File(arg[0]);
System.out.println(getfile);
madetree(0,getfile);
}
catch (ArrayIndexOutOfBoundsException e){System.out.println(e);}
}
static void madetree(int hierarchy,File dothis){
File[] farray = dothis.listFiles();
for (int i=0;i
while (k
else System.out.print("┣");
if (farray[i].isDirectory()) System.out.println("["+farray[i].getName()+"]");
else System.out.println(farray[i].getName());
if (farray[i].isDirectory()) madetree(hierarchy+1,farray[i]);
}
}
}