Java File List Load getFileList(String dir, final String extension)

Here you can find the source of getFileList(String dir, final String extension)

Description

get File List

License

Open Source License

Declaration

public static File[] getFileList(String dir, final String extension) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.util.ArrayList;

public class Main {
    private static ArrayList<File> fileList;

    public static File[] getFileList(String dir, final String extension) {

        File folder = new File(dir);

        fileList = new ArrayList<File>();

        traverse(folder, extension);//from  w w w.  j  av  a2 s. co m

        File[] fileArray = new File[fileList.size()];
        fileList.toArray(fileArray);

        return fileArray;
    }

    public static final void traverse(final File f, String extension) {
        if (f.isDirectory()) {
            final File[] childs = f.listFiles();
            for (File child : childs) {
                traverse(child, extension);
            }
            return;
        }
        // if file is extension add to list
        if (f.isFile() && f.getName().toLowerCase().endsWith(extension)) {
            fileList.add(f);
        }
    }
}

Related

  1. getFileList(final List fileList, final File root, final File[] ignoreList)
  2. getFileList(final String location)
  3. getFileList(Map>> map, File dir, T key)
  4. getFileList(String dir)
  5. getFileList(String dir)
  6. getFileList(String dir, final String suffix)
  7. getFileList(String directory, String filterRegexp)
  8. getFileList(String directoryPath)
  9. getFileList(String filePath, FileFilter fileFilter, boolean recursive)