Here you can find the source of getFilesFromDirectory(Path directory, List
private static void getFilesFromDirectory(Path directory, List<String> filenames)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.nio.file.DirectoryIteratorException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; public class Main { private static void getFilesFromDirectory(Path directory, List<String> filenames) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) { for (Path file : stream) { //System.out.println(file.getFileName() + ":"+file.getFileName().toString().endsWith("/")); if (file.getFileName().toString().endsWith("/")) { getFilesFromDirectory(file, filenames); } else { // System.out.println(file.getFileName()); filenames.add(directory.toString() + file.getFileName() + ""); // filenames.add(file.getFileName() + ""); }/*from w w w. j a v a 2 s. c o m*/ } } catch (IOException | DirectoryIteratorException x) { // IOException can never be thrown by the iteration. // In this snippet, it can only be thrown by // newDirectoryStream. System.err.println(x); } } }