Here you can find the source of getCanonicalFiles2List(List
public static List<String> getCanonicalFiles2List(List<String> path, String[] allowedExtension)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Main { public static List<String> getCanonicalFiles2List(List<String> path, String[] allowedExtension) { List<String> r = new ArrayList<String>(); for (String p : path) { List<String> r2 = new ArrayList<String>(); File rfolder = new File(p); if (rfolder.exists() && rfolder.isDirectory()) { File[] files = rfolder.listFiles(); for (File f : files) { if (f.isFile() && !f.getName().startsWith(".")) { if (allowedExtension.length > 0) { if (isAllowedExtension(f.getName(), allowedExtension)) { r2.add(p + "/" + f.getName()); }//from w w w . ja v a 2 s .co m } else { r2.add(p + "/" + f.getName()); } } } r.addAll(r2); } } return r; } public static List<String> getCanonicalFiles2List(String[] path, String[] allowedExtension, boolean checkExt) { List<String> r = new ArrayList<String>(); for (String p : path) { List<String> r2 = new ArrayList<String>(); File rfolder = new File(p); if (rfolder.exists() && rfolder.isDirectory()) { File[] files = rfolder.listFiles(); for (File f : files) { if (!checkExt || isAllowedExtension(f.getName(), allowedExtension)) { try { r2.add(f.getCanonicalPath()); } catch (IOException e) { e.printStackTrace(); } } } r.addAll(r2); } } return r; } public static File[] listFiles(String path, String[] allowedExtension) { List<File> fs = getFiles(path, allowedExtension); return fs.toArray(new File[fs.size()]); } private static boolean isAllowedExtension(String fExt, String[] allowedExtension) { for (String ext : allowedExtension) { if (fExt.endsWith(ext)) return true; } return false; } public static List<File> getFiles(String path, String[] allowedExtension) { List<File> r = new ArrayList<File>(); File rfolder = new File(path); if (rfolder.exists() && rfolder.isDirectory()) { File[] files = rfolder.listFiles(); for (File f : files) { if (isAllowedExtension(f.getName(), allowedExtension)) { r.add(f); } } } return r; } }