Here you can find the source of getFiles2List(String path, String[] allowedExtension)
public static List<String> getFiles2List(String path, String[] allowedExtension)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.ArrayList; import java.util.List; public class Main { public static List<String> getFiles2List(String path, String[] allowedExtension) { List<String> r = new ArrayList<String>(); 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.getName());/*from w w w . j a v a 2s .c o m*/ } } } return r; } public static List<String> getFiles2List(String[] paths, String[] allowedExtension) { List<String> r = new ArrayList<String>(); for (String p : paths) { List<String> flist = getFiles2List(p, allowedExtension); if (!flist.isEmpty()) r.addAll(flist); } 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; } }