Here you can find the source of getAllFilesInDirectory(File dir)
public static List<File> getAllFilesInDirectory(File dir)
//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<File> getAllFilesInDirectory(File dir) { return getAllFilesInDirectory(dir, true); }//from w w w .ja va2 s . c o m public static List<File> getAllFilesInDirectory(File dir, boolean recursive) { List<File> files = new ArrayList<>(); if (dir == null) return files; File[] fileArr = dir.listFiles(); if (fileArr == null) return files; for (File f : fileArr) { files.add(f); if (recursive) { if (f.isDirectory()) files.addAll(getAllFilesInDirectory(f)); } } return files; } }