Here you can find the source of listDir(Path dir)
public static List<Path> listDir(Path dir) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.LinkedList; import java.util.List; import java.util.stream.Stream; public class Main { public static List<Path> listDir(Path dir) throws IOException { List<Path> contents = new LinkedList<>(); try (Stream<Path> list = Files.list(dir)) { list.forEach(contents::add); }/*from w w w . j ava 2s . c o m*/ return contents; } }