获取文件夹下所有文件(包括子文件)放在list<File>中

来源:互联网 发布:广源良 知乎 编辑:程序博客网 时间:2024/05/20 15:57
public static List<File> getAllFileList(File rootFile){return getAllFileList(rootFile.getAbsolutePath(), null);}
/** * 获取文件夹下所有文件(包括子文件) *  * @param filePath * @param fileList * @return */public static List<File> getAllFileList(String filePath, List<File> fileList){if (fileList == null){fileList = new ArrayList<File>();}File rootFile = new File(filePath);File[] files = rootFile.listFiles();if (files != null){for (File file : files){if (file.isDirectory()){fileList.add(file);getAllFileList(file.getAbsolutePath(), fileList);} else{fileList.add(file);}}}return fileList;}



0 0
原创粉丝点击