zoukankan      html  css  js  c++  java
  • Java读取文件夹下的所有子文件夹

     1 package demo;
     2 import java.io.File;
     3 import java.util.ArrayList;
     4 import java.util.Arrays;
     5 import java.util.List;
     6 
     7 public class Demo {
     8     
     9     @SuppressWarnings("unchecked")
    10     public static void main(String[] args) {
    11         findFile("E:\\apache-tomcat-6.0.20\\webapps\\viscms\\r");
    12 
    13     }
    14 
    15     
    16     public static void findFile(String path){
    17         File file=new File(path);
    18         File[] tempList = file.listFiles();
    19          System.out.println("该目录下对象个数:"+tempList.length);
    20          for (int i = 0; i < tempList.length; i++) {
    21            if (tempList[i].isDirectory()) {
    22             //读取某个文件夹下的所有文件夹
    23             File[] temp=tempList[i].listFiles();
    24             for (int j = 0; j < temp.length; j++) {
    25                 System.out.println("----"+temp[j]);
    26             }
    27            }
    28          }
    29     }
    30 
    31 }

    PS:这段代码没有做空指针处理,如果该文件夹不存在会出现空指针异常,请博友自行处理。

    ==========================================路漫漫其修远兮==========================================
    ======================                     知识改变生活                     ======================
    ======================                     技术改变命运                     ======================
    ======================                 我是一名普通的程序员                 ======================
    ======================       希望通过自己的努力来使自己人生更加绚烂多彩     ======================
    ==========================================吾将上下而求索==========================================
    
  • 相关阅读:
    ajax post 时 form数据serialize()
    dapper 自定义数据库字段和代码中Model字段不一致时候的mapping方法
    TImage 的一些操作
    AOP
    SSL、数字签名、CA 工作原理
    RESTFUL
    tomcat
    Hibernate
    设计模式
    Spring配置
  • 原文地址:https://www.cnblogs.com/wanying521/p/5178278.html
Copyright © 2011-2022 走看看