Java Directory to File List getAllFiles(String dir)

Here you can find the source of getAllFiles(String dir)

Description

get All Files

License

Open Source License

Declaration

public static List<File> getAllFiles(String dir) 

Method Source Code


//package com.java2s;
import java.io.File;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<File> getAllFiles(String dir) {
        return getAllFiles(new File(dir));
    }// w  w  w.j av a 2  s . co m

    public static List<File> getAllFiles(File dir) {
        if (!dir.isDirectory()) {
            throw new IllegalArgumentException("dir isn't a directory");
        }
        List<File> files = new ArrayList<>();

        for (File f : dir.listFiles()) {
            if (f.isDirectory()) {
                files.addAll(getAllFiles(f));
            } else {
                files.add(f);
            }
        }
        return files;
    }
}

Related

  1. getAllFiles(File path, List fileList, boolean recursive)
  2. getAllFiles(File root, FileFilter fileFilter)
  3. getAllFiles(File rootDirectory, FileFilter fileFilter, boolean includeSubdirectories)
  4. getAllFiles(File sourceDirectory, List fileList)
  5. getAllFiles(final String path, final String suffix, boolean recurse)
  6. getAllFiles(String dir, String extension)
  7. getAllFiles(String dir, String filePattern)
  8. getAllFiles(String directory)
  9. getAllFiles(String directory)