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     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM