記錄一個遞迴讀取linux系統中檔案路徑的方法
阿新 • • 發佈:2018-12-15
入參為要查詢的路徑,返回所有檔案的路徑列表:
public static List<File> getAllFile(String path) throws Exception { File file = new File(path); File[] files = file.listFiles(); List<File> fileList = null; if (files != null) { fileList = new ArrayList<File>(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { getAllFile(files[i].getAbsolutePath()); } else { if (!files[i].getName().contains(".crc")) { fileList.add(files[i]); } } } } System.out.println("檔案數目" + fileList.size()); return fileList; } |