Here you can find the source of getAllFiles(File directory)
Parameter | Description |
---|---|
directory | Input directory. |
public static Collection<File> getAllFiles(File directory)
//package com.java2s; /** //from w ww.ja v a 2s . com This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga) Some utility methods for arrays */ import java.io.File; import java.util.Collection; import java.util.LinkedList; public class Main { /** * Collects all non-directory files in the given input directory * (recursively). * * @param directory Input directory. * @return All non-directory files, recursively. */ public static Collection<File> getAllFiles(File directory) { Collection<File> files = new LinkedList<File>(); getAllFilesRecursively(directory, files); return files; } /** * Helper for getAllSubdirectories(directory). */ private static void getAllFilesRecursively(File directory, Collection<File> files) { for (File file : directory.listFiles()) { if (file.isDirectory()) { getAllFilesRecursively(file, files); } else { files.add(file); } } } }