标签:stringbu mave process name folder com str pytho src
第一题:题目打印:
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()) {
showTree(level + 1, file);
}
}
}
}
public static void showNameByLevel(int level) {
StringBuffer stringBuffer = new StringBuffer();
if (level > 0) {
for (int i = 0; i < level; i++) {
stringBuffer.append("\t");
}
}
if(stringBuffer.length() >0) System.out.print("|" + stringBuffer);
System.out.println("|");
if (stringBuffer.length()>0) System.out.print("|" + stringBuffer);
System.out.print("----");
}
@Test
public void c23() {
File file = new File("D:\\TOOL\\IDEASpace\\mavedome\\src\\test\\java");
// printlen(file, 0);
showTree(0, file);
}
标签:stringbu mave process name folder com str pytho src
原文地址:http://blog.51cto.com/357712148/2342053