Java Utililty Methods Folder Read by Extension

List of utility methods to do Folder Read by Extension

Description

The list of methods to do Folder Read by Extension are organized into topic(s).

Method

voidgetFiles(File baseDir, String validExtension, List files)
get Files
String[] children = baseDir.list();
if (children == null) {
} else {
    for (String filename : children) {
        File file = new File(baseDir, filename);
        if (filename.endsWith(validExtension)) {
            files.add(file);
        } else {
...
File[]getFiles(File dir, final String extension)
get Files
if (dir == null)
    return new File[0];
File[] list = dir.listFiles(new FilenameFilter() {
    @Override
    public boolean accept(File dir, String name) {
        return name.toLowerCase().endsWith(extension);
});
...
MapgetFiles(File dir, final String extension)
get Files
Map<String, File> names = new HashMap<String, File>();
if (dir == null || !dir.exists() || !dir.isDirectory()) {
    return names;
File[] files = dir.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return name.toLowerCase().endsWith("." + extension);
});
for (File file : files) {
    names.put(file.getName().substring(0, file.getName().length() - extension.length() - 1), file);
return names;
File[]getFiles(File dir, final String extensionFilter)
get Files
return dir.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return name.toLowerCase().endsWith("." + extensionFilter);
});
ListgetFiles(File dir, String fileExtension)
Returns all files in the given directory that end on fileExtension.
File[] files = dir.listFiles((f, s) -> s.endsWith(fileExtension));
return Arrays.asList(files);
File[]getFiles(File folder, String... extensions)
Return the list of Files (excluding folders) for this Folder for the given extensions.
final Set<String> exts = new HashSet<String>();
for (String ext : extensions) {
    exts.add(ext.toLowerCase());
File[] files = folder.listFiles(new FileFilter() {
    @Override
    public boolean accept(File file) {
        if (file.isDirectory()) {
...
ArrayListgetFiles(final String path, final String ext)
get Files
final File folder = new File(path);
final File[] listOfFiles = folder.listFiles();
final ArrayList<File> theFiles = new ArrayList<File>();
for (final File f : listOfFiles) {
    if (f.isFile()) {
        if (f.getName().substring(f.getName().lastIndexOf(".")).equalsIgnoreCase(ext)) {
            theFiles.add(f);
System.out.println("Found files " + theFiles);
return theFiles;
ListgetFiles(String dir, String ext)
Return list of files which match an extension.
List matchedFiles = new ArrayList();
File fileDir = new File(dir);
if (fileDir.exists()) {
    String[] files = fileDir.list();
    for (int i = 0; i < files.length; i++) {
        if (files[i].endsWith(ext))
            matchedFiles.add(files[i]);
return matchedFiles;
ListgetFiles(String dir, String... extension)
get all file which in dir
File f = new File(dir);
if (!f.isDirectory()) {
    return null;
List<File> fileList = new ArrayList<File>();
getFiles(f, fileList, extension);
return fileList;
ListgetFiles(String directory, String ext)
Get the list of specific file types in a directory
List<String> fileNames = new ArrayList<>();
try {
    File f = new File(directory);
    boolean flag = f.isDirectory();
    if (flag) {
        File fs[] = f.listFiles();
        for (int i = 0; i < fs.length; i++) {
            if (!fs[i].isDirectory()) {
...