public static void main(String[] args) {
File f = new File("d:/A");
System.out.println(f.getName());
tree(f, 1);
}
private static void tree(File f, int level) {
String preStr = "";
for(int i=0; i<level; i++) {
preStr += " ";
}
File[] childs = f.listFiles();
for(int i=0; i<childs.length; i++) {
System.out.println(preStr + childs[i].getName());
if(childs[i].isDirectory()) {
tree(childs[i], level + 1);
}
}
}
}
File f = new File("d:/A");
System.out.println(f.getName());
tree(f, 1);
}
private static void tree(File f, int level) {
String preStr = "";
for(int i=0; i<level; i++) {
preStr += " ";
}
File[] childs = f.listFiles();
for(int i=0; i<childs.length; i++) {
System.out.println(preStr + childs[i].getName());
if(childs[i].isDirectory()) {
tree(childs[i], level + 1);
}
}
}
}
解决方案 »
- 关于sql语句插入的问题
- jdbc 操作oracle数据库出错
- 比较难的问题,应用程序中如何调用 window.open
- DATE和DAY_OF_MONTH有啥区别
- java生成jpeg/png图片时,如何设置图片质量?
- 弱弱的请教:Borland Socket Server有什么用?
- 哪位朋友对transaction比较有经验,有几个问题想请教一下
- 请讲一讲使用递归方法算阶乘!谢谢!!有个例子不明白!!
- 实在是不能理解,谁能帮我解释解释!
- synchronizeed(expr).expr应诶是什么样的类型。为什么我用一个int的,会出错。说incompatible types
- 两段实现相同功能的代码,设计不同,帮我看下那个版本的效率高点。
- 请问,如何清除cookie里面的值???
判断下 childs 是否为空再用吧
File[] childs = f.listFiles();
File[] childs = f.listFiles();
for(int i=0; i<childs.length; i++) {
listChilds(childs[i], level + 1);
}
lz可以先加个判断:
if (f.exists()) {
//...
}else {
f.create();
}
之类的