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     }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章