java 遍历目录
时间:2014-05-03 16:07:04
收藏:0
阅读:265
package com.recursion;
import java.io.File;
public class RecursionFile {
public static void main(String[] args) {
File file = new File("G:/A");
tree(file, 0);
}
private static void tree(File file, int level) {
StringBuffer stringBuffer = new StringBuffer("");
for (int i = 0; i< level; i++) {
stringBuffer.append("-");
}
File[] childs = file.listFiles();
for (int i = 0; i<childs.length; i++) {
System.out.println(stringBuffer+childs[i].getName());
if (childs[i].isDirectory()) {
tree(childs[i], level+1);
}
}
}
}
import java.io.File;
public class RecursionFile {
public static void main(String[] args) {
File file = new File("G:/A");
tree(file, 0);
}
private static void tree(File file, int level) {
StringBuffer stringBuffer = new StringBuffer("");
for (int i = 0; i< level; i++) {
stringBuffer.append("-");
}
File[] childs = file.listFiles();
for (int i = 0; i<childs.length; i++) {
System.out.println(stringBuffer+childs[i].getName());
if (childs[i].isDirectory()) {
tree(childs[i], level+1);
}
}
}
}
评论(0)