Java Directory to File List getAllFilesWithExtension(String folderPath, String extension)

Here you can find the source of getAllFilesWithExtension(String folderPath, String extension)

Description

get All Files With Extension

License

Open Source License

Declaration

public static Iterable<File> getAllFilesWithExtension(String folderPath, String extension) 

Method Source Code

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

import java.io.File;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;

public class Main {
    public static Iterable<File> getAllFilesWithExtension(String folderPath, String extension) {
        File folder = new File(folderPath);
        File[] files = folder.listFiles();
        if (files == null) {
            return new ArrayList<>();
        }//from   w  w w  . java  2 s .  co  m

        return Arrays.asList(files).stream()
                .filter(file -> file.isFile() && file.getName().toLowerCase().endsWith(extension.toLowerCase()))
                .collect(Collectors.toList());
    }
}

Related

  1. getAllFilesMatchingThisPatternIgnoreCase(String sDirectoryPath, String sPattern)
  2. getAllFilesPresentInFolder(File srcPath)
  3. getAllFilesRecursively(File dir, List filelist)
  4. getAllFilesRecursively(File directory, Collection files)
  5. getAllFilesWithExtension(String directory, final String extension)
  6. getAllFilesWithFilter(String DirectoryName, FilenameFilter Filter)