Java递归目录结构
2016-06-08 17:55
429 查看
import java.io.File; public class FileTree { public static void main(String[] args) { printFileTree("D:\\AAAAASSOCWEBDATA",0); } public static void printFileTree(String driver, int level) { File file = new File(driver); printByLevel(file.getName(),level); if (file.exists()) { if(file.isDirectory()){ File[] children = file.listFiles(); for (int i = 0; i < children.length; i++) { printFileTree(children[i].getPath(),level+1); } } } } public static void printByLevel(String name,int level) { for (int i = 0; i < level; i++) { System.out.print(" "); } System.out.println("|-〄"+name); } }
结果如下 |-〄AAAAASSOCWEBDATA |-〄bom |-〄320923198906262416 |-〄320923198906262416.jpg |-〄81696e7ae8034cafa3d1c96d9c10f04f.jpg |-〄f395ef2b4038442a9b97e1c54362be0c.jpg |-〄contact |-〄t.docx |-〄video
相关文章推荐
- RxJava初探
- hihocoder 1080更为复杂的买卖房屋姿势 java实现
- android studio项目如何导入到eclipse中
- 电商之梳理servlet知识---javaweb基础
- java根据图片url下载图片到本地
- springMVC 页面传入日期报错问题处理:org.springframework.validation.BindException: org.springframework.validation.
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- eclipse迁移到android studio
- Eclipse自定义注释
- Exception in thread "main" java.beans.IntrospectionException: Method not found: isWBLDINST
- 在JAVA中如何跳出当前的多重嵌套循环
- Java中出现No enclosing instance of type XXX is accessible问题
- @NotEmpty、@NotBlank、@NotNull
- spring中MessageSource的配置使用方法--ResourceBundleMessageSource
- java关键字Transient
- 在Eclipse中创建Maven多模块工程的例子
- java中short s1 = 1;s1 = s1 + 1;会出错而short s1+=1;能编译通过的原因
- 使用CXF和spring搭建webService服务
- SpringMVC框架中的过滤器设置
- Spring整合Hessian