java获取文件夹下所有目录

public void getList(String patha){
        String path=patha;
          File file=new File(path);
          File[] tempList = file.listFiles();
          System.out.println("该目录下对象个数:"+tempList.length);
          List<Map<String, String>> list = new ArrayList<Map<String,String>>();
          for (int i = 0; i < tempList.length; i++) {
           if (tempList[i].isFile()) {
              
            System.out.println("文     件:"+tempList[i]);
           }
           if (tempList[i].isDirectory()) {
            System.out.println("文件夹:"+tempList[i].getPath());
           
            //递归:
            getList(tempList[i].getPath());
           }
          }
    }

 

posted @ 2020-08-05 11:12  不懂技术的雷  阅读(3019)  评论(1编辑  收藏  举报