java 遍历目录

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

java 遍历目录

上一篇:Java Swing 之设置窗体背景图片


下一篇:JAVA之IO技术键盘录入 System.in