Here you can find the source of getFilesList(Path directory, Set
public static List<Path> getFilesList(Path directory, Set<String> extensions) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; public class Main { public static List<Path> getFilesList(Path directory, Set<String> extensions) throws IOException { try (Stream<Path> stream = Files.list(directory)) { List<Path> list = stream.filter(path -> extensions.contains(getFileExtension(path))) .collect(Collectors.toList()); return list; }//from w w w .ja va 2 s.co m } public static String getFileExtension(Path file) { String filename = file.getFileName().toString(); return filename.substring(filename.lastIndexOf('.') + 1); } }