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);
}
}
}
}

java 遍历目录,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!