Java Utililty Methods File List Load

List of utility methods to do File List Load

Description

The list of methods to do File List Load are organized into topic(s).

Method

File[]getFileList(String path, String filterName)
get File List
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;
        if (file.getName().endsWith(filterName)) {
...
String[]getFileList(String path, String regex)
Gets the file list.
final File dir = new File(path);
class PatternFilter implements FilenameFilter {
    final String regexExpression;
    public PatternFilter(String regex) {
        regexExpression = regex;
    @Override
    public boolean accept(File f, String name) {
...
VectorgetFileList(String path, String searchString)
Returns the fileList.
Vector<File> fileList = new Vector<File>();
File dir = new File(path);
File[] files = dir.listFiles();
if (files != null) {
    for (int i = 0; i < files.length; i++) {
        if (files[i].getName().contains(searchString)) {
            fileList.add(files[i]);
    Collections.sort(fileList);
    return fileList;
return null;
File[]getFileList(String s)
Get a list of the files in a directory
List<File> ret = new ArrayList<File>();
if (isDirectory(s)) {
    File[] files = new File(s).listFiles();
    if (files != null) {
        for (File f : files) {
            if (f.isFile()) {
                ret.add(f);
File[] out = new File[ret.size()];
out = ret.toArray(out);
return out;
ArrayListgetFileList(String zipFilePath)
Obtains an ArrayList of the contents of the zip file (files and directories).
java.util.ArrayList<String> sArray = new java.util.ArrayList<String>();
ZipFile zFile = new ZipFile(zipFilePath);
Enumeration<? extends ZipEntry> entries = zFile.entries();
while (entries.hasMoreElements()) {
    ZipEntry entry = entries.nextElement();
    String filePath = entry.getName();
    sArray.add(filePath);
return sArray;
ListgetFileListByDFS(File file)
get File List By DFS
Stack<File> stack = new Stack<File>();
stack.push(file);
File fileInStack = null;
List<File> fileList = new ArrayList<File>();
while (!stack.isEmpty()) {
    fileInStack = stack.pop();
    File[] files = fileInStack.listFiles();
    for (File eachFile : files) {
...
String[]getFileListByExtension(final String location, final String extension)
get File List By Extension
File file = new File(location);
if (file.isDirectory()) {
    String[] lists = file.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (name.endsWith(extension.toLowerCase()) || name.endsWith(extension.toUpperCase())) {
                return true;
            return false;
...
String[]getFileListByRegex(String dir, final String regex)
Get the File list under the given directory by the regex.
File file = new File(dir);
if (!file.isDirectory()) {
    return null;
FilenameFilter filter = new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return name.matches(regex);
};
return file.list(filter);
SetgetFileListDeep(File path)
get File List Deep
Set<String> set = new TreeSet<String>();
if (path.isDirectory()) {
    String[] files = path.list();
    for (String file : files) {
        walkInDirForFiles(path, file, set);
} else {
    set.add(path.toString());
...
File[]getFileListInFolder(String path)
get File List In Folder
ArrayList<File> results = new ArrayList<>();
File[] files = new File(path).listFiles();
for (File file : files) {
    if (file.isFile()) {
        results.add(file);
return results.toArray(new File[0]);
...