Here you can find the source of listFiles(Path path, List
private static void listFiles(Path path, List<Path> preorderList)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.nio.file.Path; import java.util.List; public class Main { private static void listFiles(Path path, List<Path> preorderList) { preorderList.add(path);//from ww w . jav a 2 s. c o m File[] listFiles = path.toFile().listFiles(); if (listFiles != null) for (File child : listFiles) { listFiles(child.toPath(), preorderList); } } }