50,345
社区成员




public class FolderTreeTest {
/**
* @param args
*/
public static void main(String[] args) {
String rootFolderPath = "D:\\ROOT_FOLDER";
FolderTreeTest.showTree(0,new File(rootFolderPath));
}
public static void showTree(int level,File parentFolderPath){
if(parentFolderPath.isDirectory()){
File[] childFiles = parentFolderPath.listFiles();
for(File file : childFiles){
showNameByLevel(level);
System.out.println(file.getName());
if(file.isDirectory()){
FolderTreeTest.showTree(level + 1,file);
}
}
}
}
public static void showNameByLevel(int level){
StringBuffer spaceStr = new StringBuffer();
if(level > 0){
for(int i = 0 ; i < level ; i ++){
spaceStr.append(" ");
}
}
if(spaceStr.length() > 0)System.out.print("|" + spaceStr);
System.out.println("|");
if(spaceStr.length() > 0)System.out.print("|" + spaceStr);
System.out.print("----");
}
}