Java Path File Extention nio listFiles(final Path path, final String... extensions)

Here you can find the source of listFiles(final Path path, final String... extensions)

Description

List all files with extension

License

Open Source License

Parameter

Parameter Description
path the folder path
extensions the extension without '.'

Exception

Parameter Description
IOException an exception

Return

list of all files in the folder that have the extension

Declaration

public static List<Path> listFiles(final Path path, final String... extensions) throws IOException 

Method Source Code

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

import java.io.IOException;

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

import java.util.List;

import java.util.stream.Collectors;

public class Main {
    /**//from www .jav  a 2s . com
     * List all files with extension
     *
     * @param path       the folder path
     * @param extensions the extension without '.'
     * @return list of all files in the folder that have the extension
     * @throws IOException
     */
    public static List<Path> listFiles(final Path path, final String... extensions) throws IOException {
        return Files.list(path).filter(child -> {
            if (extensions.length > 0) {
                for (String extension : extensions) {
                    if (child.getFileName().toString().endsWith(extension)) {
                        return true;
                    }
                }
                return false;
            } else {
                return true;
            }
        }).collect(Collectors.toList());
    }
}

Related

  1. getPath(String outputDir, String qualifiedFilename, String fileextension)
  2. getTransformedOutputPath(Path input, String compressExtension, String outputDir)
  3. hasExtensionIgnoreCase(Path path, String ext)
  4. insertSuffixBeforeExtension(String path, String suffix)
  5. listFile(final String path, final String extension)
  6. listFiles(String path, String extension)
  7. removeExtension(final Path path)
  8. removeExtension(Path file)
  9. replaceExtensionWith(String toFilePath, String newExtension)