Here you can find the source of getFiles(File folder)
public static List<File> getFiles(File folder)
//package com.java2s; //License from project: Apache License import java.io.File; import java.util.ArrayList; import java.util.List; public class Main { public static List<File> getFiles(File folder) { List<File> files = new ArrayList<File>(); iterateFolder(folder, files);//w w w.j a va2 s.c o m return files; } private static void iterateFolder(File folder, List<File> files) { File flist[] = folder.listFiles(); files.add(folder); if (flist == null || flist.length == 0) { files.add(folder); } else { for (File f : flist) { if (f.isDirectory()) { iterateFolder(f, files); } else { files.add(f); } } } } }