Java File List Load getFileList(String path, String filterName)

Here you can find the source of getFileList(String path, String filterName)

Description

get File List

License

Open Source License

Declaration

public static File[] getFileList(String path, String filterName) 

Method Source Code


//package com.java2s;
import java.io.*;
import java.util.*;

public class Main {
    public static File[] getFileList(String path, String filterName) {
        List<File> fileList = new ArrayList<File>();
        File[] files = new File(path).listFiles();

        if (!filterName.equals("") && filterName != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    continue;
                }/* www . j  ava 2 s .  c o  m*/

                if (file.getName().endsWith(filterName)) {
                    fileList.add(file);
                }
            }
        } else {
            for (File file : files) {
                if (file.isDirectory()) {
                    continue;
                }
                fileList.add(file);
            }
        }

        File[] resultFileList = null;
        if (fileList != null && fileList.size() > 0) {
            resultFileList = new File[fileList.size()];

            for (int i = 0; i < fileList.size(); i++) {
                resultFileList[i] = fileList.get(i);
            }
        }

        return resultFileList;
    }
}

Related

  1. getFileList(String path)
  2. getFileList(String path)
  3. getFileList(String path)
  4. getFileList(String path)
  5. getFileList(String path)
  6. getFileList(String path, String regex)
  7. getFileList(String path, String searchString)
  8. getFileList(String s)
  9. getFileList(String zipFilePath)