Here you can find the source of listFiles(final Path path, final String... extensions)
Parameter | Description |
---|---|
path | the folder path |
extensions | the extension without '.' |
Parameter | Description |
---|---|
IOException | an exception |
public static List<Path> listFiles(final Path path, final 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.stream.Collectors; public class Main { /**//from www .jav a 2s . com * List all files with extension * * @param path the folder path * @param extensions the extension without '.' * @return list of all files in the folder that have the extension * @throws IOException */ public static List<Path> listFiles(final Path path, final String... extensions) throws IOException { return Files.list(path).filter(child -> { if (extensions.length > 0) { for (String extension : extensions) { if (child.getFileName().toString().endsWith(extension)) { return true; } } return false; } else { return true; } }).collect(Collectors.toList()); } }