06_1_列出文件目录树
06_1_列出文件目录树
1. 例子
package Test; import java.io.File; public class TestFileList { public static void main(String[] args) { File f = new File("D:/桌面/桌面/01开发/项目管理"); /* for (int i = 0; i < f.listFiles().length; i++) { System.out.println(f.listFiles()[i]); for (int j = 0; j < new File(f.listFiles()[i]+"").listFiles().length; j++) { System.out.println(" " + new File(f.listFiles()[i]+"").listFiles()[j] ); } }*/ tree(f, 0); } public static void tree(File f, int level) { File[] children = f.listFiles(); String str = ""; for (int i = 0; i < level; i++) { str += " "; } for (int i = 0; i < children.length; i++) { System.out.println(str + children[i].getName()); if(children[i].isDirectory()) { tree(children[i], level+1); } } } }
有什么问题可以联系我,大家一起研究,共同进步。