Here you can find the source of getAllFiles(File dir)
public static List<File> getAllFiles(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> getAllFiles(File dir) { List<File> result = new ArrayList<>(); getAllFilesAux(dir, result);// ww w. j ava 2s . co m return result; } private static void getAllFilesAux(File dir, List<File> result) { File[] files = dir.listFiles(); if (files == null) { return; } for (File file : files) { if (file.isDirectory()) { getAllFilesAux(file, result); } else if (file.isFile()) { result.add(file); } } } }