Here you can find the source of getFiles(Collection
Parameter | Description |
---|---|
folders | A collection of folders to get all files from |
public static Collection<File> getFiles(Collection<File> folders)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; import java.util.List; public class Main { /**/*from w w w.j a va2s.c om*/ * This method recursively gets a collection of all the files in a collection * of folders/files. * * @param folders * A collection of folders to get all files from * @return A list of all files in a folder */ public static Collection<File> getFiles(Collection<File> folders) { List<File> fileList = new LinkedList<File>(); for (File folder : folders) { if (folder.isDirectory()) { for (File f : folder.listFiles()) { if (f.isDirectory()) fileList.addAll(getFiles(f)); else fileList.add(f); } } else { fileList.add(folder); } } return fileList; } /** * This method recursively gets a collection of all the files in a single * folder * * @param folder * A folder to get all files from * @return A list of all files in a folder (null if input is not a folder) */ public static Collection<File> getFiles(File folder) { if (!folder.isDirectory()) return null; List<File> folderList = new ArrayList<File>(1); folderList.add(folder); return getFiles(folderList); } }