Here you can find the source of getFiles(File dir, File... excludes)
public static List<String> getFiles(File dir, File... excludes)
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static List<String> getFiles(File dir, File... excludes) { List<String> result = new ArrayList<String>(); File[] aFiles = dir.listFiles(); List<File> files = Arrays.asList(aFiles); for (File file : files) { boolean exclude = false; for (File f : excludes) { if (file.getAbsolutePath().startsWith(f.getAbsolutePath())) { exclude = true;//w w w. j a va2 s . c o m break; } } if (!exclude) { result.add(file.getAbsolutePath()); if (!file.isFile()) { List<String> deeperList = getFiles(file, excludes); result.addAll(deeperList); } } } return result; } }