Here you can find the source of listFile(final String path, final String extension)
public static List<String> listFile(final String path, final String extension) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; public class Main { public static List<String> listFile(final String path, final String extension) throws IOException { if (!new File(path).isDirectory()) { throw new IllegalArgumentException("Path " + path + " is not a directory"); }/*from w ww. j a va2 s .com*/ final List<String> files = new ArrayList<>(); Files.walk(Paths.get(path)).filter(Files::isRegularFile) .filter((p) -> p.toFile().getAbsolutePath().endsWith(extension)) .forEach(p -> files.add(p.toString())); return files; } }