Here you can find the source of getAllFiles(File dir, List
public static boolean getAllFiles(File dir, List<File> fileList)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.util.List; public class Main { public static boolean getAllFiles(File dir, List<File> fileList) { try {//from ww w .ja va2s.c o m File[] files = dir.listFiles(); for (File file : files) { fileList.add(file); if (file.isDirectory()) { System.out.println("directory:" + file.getCanonicalPath()); getAllFiles(file, fileList); } else { System.out.println(" file:" + file.getCanonicalPath()); } } } catch (IOException e) { e.printStackTrace(); return false; } return true; } }