Here you can find the source of getAllFiles(String dir)
public static List<File> getAllFiles(String dir)
//package com.java2s; import java.io.File; import java.util.ArrayList; import java.util.List; public class Main { public static List<File> getAllFiles(String dir) { return getAllFiles(new File(dir)); }// w w w.j av a 2 s . co m public static List<File> getAllFiles(File dir) { if (!dir.isDirectory()) { throw new IllegalArgumentException("dir isn't a directory"); } List<File> files = new ArrayList<>(); for (File f : dir.listFiles()) { if (f.isDirectory()) { files.addAll(getAllFiles(f)); } else { files.add(f); } } return files; } }