Here you can find the source of getFiles(File directory, boolean recursive)
public static List<File> getFiles(File directory, boolean recursive)
//package com.java2s; import java.io.File; import java.util.ArrayList; import java.util.List; public class Main { public static List<File> getFiles(File directory, boolean recursive) { if (!directory.isDirectory()) { throw new AssertionError(directory + " is not a directory!"); }/* w w w . j a va2 s . c om*/ List<File> files = new ArrayList<>(); for (File f : directory.listFiles()) { if (f.isDirectory() && recursive) { files.addAll(getFiles(f, recursive)); } else { files.add(f); } } return files; } }