Here you can find the source of getFiles(File file, Collection
private static void getFiles(File file, Collection<File> ret)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.Collection; import java.util.HashSet; import java.util.Set; public class Main { /**/*from w ww . j a v a2s .com*/ * Gets all files under a given root * * @param root a root directory/file * @return all files under the given root */ public static Set<File> getFiles(File root) { Set<File> ret = new HashSet<File>(); getFiles(root, ret); return ret; } private static void getFiles(File file, Collection<File> ret) { if (file.isDirectory()) { for (File f : file.listFiles()) getFiles(f, ret); } else ret.add(file); } }