Here you can find the source of getAllPaths(Path root, final String... extensions)
public static List<Path> getAllPaths(Path root, final String... extensions)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; public class Main { public static List<Path> getAllPaths(Path root, final String... extensions) { List<Path> l = new ArrayList<>(); getAllPaths(l, root, extensions); return l; }//from ww w.j a v a2s .c o m public static void getAllPaths(final List<Path> paths, Path root, final String... extensions) { try { Files.walkFileTree(root.toAbsolutePath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Files.isRegularFile(file) && isSupportedFile(file, extensions)) { paths.add(file); } return FileVisitResult.CONTINUE; } private boolean isSupportedFile(Path file, String[] extensions) { for (String ext : extensions) { if (file.toString().toLowerCase().endsWith("." + ext)) { return true; } } return false; } }); } catch (IOException e) { // return; } } }