Java 读取某个目录下所有文件、文件夹

 1 /**
 2     * @Author:
 3     * @Description:获取某个目录下所有直接下级文件,不包括目录下的子目录的下的文件,所以不用递归获取
 4     * @Date:
 5     */
 6     public static List<String> getFiles(String path) {
 7         List<String> files = new ArrayList<String>();
 8         File file = new File(path);
 9         File[] tempList = file.listFiles();
10 
11         for (int i = 0; i < tempList.length; i++) {
12             if (tempList[i].isFile()) {
13                 files.add(tempList[i].toString());
14                 //文件名,不包含路径
15                 //String fileName = tempList[i].getName();
16             }
17             if (tempList[i].isDirectory()) {
18                 //这里就不递归了,
19             }
20         }
21         return files;
22     }

 

posted @ 2019-08-15 21:35  全力以赴001  阅读(8453)  评论(0编辑  收藏  举报