[java]代码库
package com.syz.file;
import java.io.File;
public class ListFloder {
public static void main(String[] args) {
printFiles(new File("E:\\Java workplace"),1);
}
public static void printFiles(File file,int tab){ //tab用于文件打印时的缩进
if (file.isDirectory()) {
File next[]=file.listFiles();
for (int i = 0; i < next.length; i++) {
for (int j = 1; j < tab; j++) {
System.out.print("|--");
}
System.out.println(next[i].getName());
if (next[i].isDirectory()) {
printFiles(next[i], tab+1); //递归,next[i]为file的子目录,故tab+1
}
}
}
}
}
中级程序员
by: 东城 发表于:2016-05-12 09:20:37 顶(0) | 踩(0) 回复
回复评论