遍歷目錄文件
阿新 • • 發佈:2017-09-07
rect ted logs gen todo mps log get dep
public static List<String> listFile(List<String> lstFileNames, File f, String suffix, boolean isdepth) { // 若是目錄, 采用遞歸的方法遍歷子目錄 try { if (f.isDirectory()) { File[] t = f.listFiles(); for (int i = 0; i < t.length; i++) { if (isdepth || t[i].isFile()) { listFile(lstFileNames, t[i], suffix, isdepth); } } } else { String filePath = f.getPath(); if (!suffix.equals("")) { int begIndex = filePath.lastIndexOf("."); String tempsuffix = ""; if (begIndex != -1) { tempsuffix = filePath.substring(begIndex + 1, filePath.length()); if (suffix.contains("." + tempsuffix + ".")) { System.out.println("filePath:"+filePath); lstFileNames.add(filePath); } } } else { lstFileNames.add(filePath); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return lstFileNames; }
遍歷目錄文件