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     }

 

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