Here you can find the source of getAllFilesInFolderAndSubFolders(String folder)
public static String[] getAllFilesInFolderAndSubFolders(String folder)
//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 String[] getAllFilesInFolderAndSubFolders(String folder) { List<File> filesToCheck = new ArrayList<File>(); File file = load(folder); if (file != null) { if (file.exists()) { if (file.isDirectory()) { for (File f : file.listFiles()) { filesToCheck.add(f); }//from w w w.ja v a 2 s. c o m } } boolean foldersInList = true; while (foldersInList) { List<File> remove = new ArrayList<File>(); List<File> toCheck = new ArrayList<File>(); for (File f : filesToCheck) { if (f.isDirectory()) { remove.add(f); for (File fi : f.listFiles()) { toCheck.add(fi); } } } for (File f : toCheck) { filesToCheck.add(f); } for (File f : remove) { filesToCheck.remove(f); } if (remove.size() == 0) { foldersInList = false; } } String[] files = new String[filesToCheck.size()]; for (int i = 0; i < files.length; i++) { files[i] = filesToCheck.get(i).getPath(); } return files; } return new String[] {}; } public static File load(String filePath) { File file = new File(filePath); if (file.exists()) { return file; } return null; } public static boolean isDirectory(String filePath) { File file = load(filePath); if (file != null) { return file.isDirectory(); } return false; } }