Here you can find the source of getAllFilesRecursively(File dir, List
private static void getAllFilesRecursively(File dir, List<File> filelist)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.File; import java.util.List; public class Main { private static void getAllFilesRecursively(File dir, List<File> filelist) { File[] files = dir.listFiles(); if (files == null) { return; }// w w w .jav a2s . c o m int i; for (i = 0; i < files.length; ++i) { if (files[i].isFile()) { filelist.add(files[i]); } else if (files[i].isDirectory()) { getAllFilesRecursively(files[i], filelist); } } } }