/** * 读取某个文件夹下的所有文件 返回文件路径集合 * @param filepath 文件夹名 * @return */
public static List<String> readfile(String filepath) { List<String> list=new ArrayList<>(); try { File file = new File(filepath); if (!file.isDirectory()) { list.add(file.getPath()); } else if (file.isDirectory()) { String[] filelist = file.list(); for (int i = 0; i < filelist.length; i++) { File readfile = new File(filepath + "\\" + filelist[i]); if (!readfile.isDirectory()) { list.add(readfile.getPath()); } else if (readfile.isDirectory()) { readfile(filepath + "\\" + filelist[i]); } } } } catch (Exception e) { System.out.println("readfile() Exception:" + e.getMessage()); } return list; }