Java Path File List nio list(final Path directory)

Here you can find the source of list(final Path directory)

Description

A list of the entries in the directory.

License

Open Source License

Parameter

Parameter Description
directory The directory to list the entries for

Return

The list of entries

Declaration

public static List<Path> list(final Path directory) throws IOException 

Method Source Code

//package com.java2s;
/*/*  w  w w  .j a v a2 s .  co m*/
 * eXist Open Source Native XML Database
 * Copyright (C) 2001-2015 The eXist Project
 * http://exist-db.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

import java.io.IOException;
import java.nio.file.*;

import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    /**
     * A list of the entries in the directory. The listing is not recursive.
     *
     * @param directory The directory to list the entries for
     *
     * @return The list of entries
     */
    public static List<Path> list(final Path directory) throws IOException {
        try (final Stream<Path> entries = Files.list(directory)) {
            return entries.collect(Collectors.toList());
        }
    }

    /**
     * A list of the entries in the directory. The listing is not recursive.
     *
     * @param directory The directory to list the entries for
     * @param filter A filter to be applied to the list
     * @return The list of entries
     */
    public static List<Path> list(final Path directory, final Predicate<Path> filter) throws IOException {
        try (final Stream<Path> entries = Files.list(directory).filter(filter)) {
            return entries.collect(Collectors.toList());
        }
    }
}

Related

  1. getPreorderList(Path root)
  2. getSortedPathList(final Path dir, final boolean dirsFirst)
  3. getTables(final List d1)
  4. isBlackListedDirectory(Path path)
  5. isPlaylistFile(Path testFile)
  6. list(Path basePath)
  7. listChildren(Path dir)
  8. listChildren(Path dir, boolean searchDirectory)
  9. listChildren(Path directory)