Here you can find the source of getAllFiles(File path, List
Parameter | Description |
---|---|
path | absolute path of a folder |
fileList | a list to collect the files |
recursive | if <code>true</code>, find the files in sub folders as well |
public static void getAllFiles(File path, List<File> fileList, boolean recursive)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import java.io.File; import java.util.List; public class Main { /**/*from www . ja va 2 s . c o m*/ * Gets all files in a specified path. * * @param path * absolute path of a folder * @param fileList * a list to collect the files * @param recursive * if <code>true</code>, find the files in sub folders as well */ public static void getAllFiles(File path, List<File> fileList, boolean recursive) { if (path.isDirectory()) { File[] files = path.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { fileList.add(files[i]); } else if (recursive) { getAllFiles(files[i], fileList, recursive); } } } } } }