遍历文件夹 非递归 只收集指定后缀的文件

public List<File> listSpecifFile(String path, final String suffix) { List<File> files = new ArrayList<File>(); LinkedList<File> list = new LinkedList<File>(); File dir = new File(path); list.add(dir); File tmp; while (!list.isEmpty()) { tmp = (File) list.removeFirst(); File[] file = tmp.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.getName().endsWith(suffix); } }); for (int i = 0; i < file.length; i++) { if (file[i].isDirectory()) list.add(file[i]); else System.out.println(file[i].getAbsolutePath()); files.add(file[i]); } } return files; }

你可能感兴趣的:(String,list,File,Path)