import java.io.File;
public class Test {
/**
* @param args
* @author itmyhome
*/
public static void main(String[] args) {
File f = new File("F:/javaAPI/JavaAPI1.6/java/awt");
printFile(f, 0);
}
public static void printFile(File f, int len) {
String str = "";
for (int i = 0; i < len; i++) {
str += " "; // 路径空格,以便更好的展现层次结构
}
File file[] = f.listFiles();
for (int i = 0; i < file.length; i++) {
System.out.println(str + file[i].getName());
if (file[i].isDirectory()) {
printFile(file[i], len + 1);
}
}
}
}
作者:itmyhome