Java Path File List nio fileListDeep(Path dir)

Here you can find the source of fileListDeep(Path dir)

Description

file List Deep

License

LGPL

Declaration

public static ArrayList<Path> fileListDeep(Path dir) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import java.util.ArrayList;
import java.util.Iterator;

import java.util.stream.Stream;

public class Main {
    public static ArrayList<Path> fileListDeep(Path dir) {
        try {//from w w w .jav  a2s .c  o  m
            if (Files.exists(dir)) {
                Stream<Path> ds = Files.walk(dir);

                ArrayList<Path> dirList = new ArrayList<Path>();

                Iterator<Path> it = ds.iterator();
                while (it.hasNext()) {
                    Path tp = it.next();
                    // discard directories
                    if (!Files.isDirectory(tp)) {
                        dirList.add(tp);
                    }
                }
                ds.close();
                return dirList;
            } else {
                return null;
            }

        } catch (IOException e) {
            System.out.println("Could not traverse directory");
        }
        return null;
    }
}

Related

  1. archive(Path archive, List targetFiles)
  2. asFileList(Object... paths)
  3. asPathsList(final File[] files)
  4. compileTreeWithErrors(JavaCompiler compiler, List options, File targetFolder, DiagnosticListener diagnosticListener, boolean addProcessorsToClasspath)
  5. deepListChildren(Path directory)
  6. findExpectedResultForTestcase(final Path testcase, final LinkedList expectedResults)
  7. getClassLoaderFromPaths(ArrayList paths)
  8. getDirectoryList(Path basePath)
  9. getPreorderList(Path root)