Java Path File Name nio getAllFiles(List fileNames, Path path)

Here you can find the source of getAllFiles(List fileNames, Path path)

Description

Collect all the files in a given path recursively

License

Open Source License

Parameter

Parameter Description
fileNames a parameter
path a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static List<String> getAllFiles(List<String> fileNames, Path path) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

public class Main {
    /**/*from  ww w  . j a v a2s . co m*/
     * Collect all the files in a given path recursively 
     * 
     * @param fileNames
     * @param path
     * @return
     * @throws IOException 
     */
    public static List<String> getAllFiles(List<String> fileNames, Path path) throws IOException {

        try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
            for (Path subPath : stream) {
                if (subPath.toFile().isDirectory()) {
                    getAllFiles(fileNames, subPath);
                } else {
                    String fileName = subPath.toAbsolutePath().toString();

                    //getLogger().info(String.format("File type: %s - %s", getFileType(fileName), fileName));

                    fileNames.add(fileName);
                }
            }
        } catch (IOException e) {
            throw e;
        }

        return fileNames;
    }
}

Related

  1. findUpward(String filename, Path startingPath)
  2. formatPathName(Path path)
  3. getAbsolutePath(String fileName)
  4. getAbsolutePath(String name)
  5. getAbsolutePathName(File dir)
  6. getArtifactName(Path artifactPath)
  7. getBandNameStr(Path filePath)
  8. getClassName(Path pluginImplementationDirectory, Path classFile)
  9. getConfigurationFile(String installPath, String serverName)