Java Path File Extention nio listFile(final String path, final String extension)

Here you can find the source of listFile(final String path, final String extension)

Description

list File

License

Open Source License

Declaration

public static List<String> listFile(final String path, final String extension) throws IOException 

Method Source Code


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

import java.io.File;

import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Paths;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> listFile(final String path, final String extension) throws IOException {
        if (!new File(path).isDirectory()) {
            throw new IllegalArgumentException("Path " + path + " is not a directory");
        }/*from   w ww. j  a  va2 s  .com*/

        final List<String> files = new ArrayList<>();

        Files.walk(Paths.get(path)).filter(Files::isRegularFile)
                .filter((p) -> p.toFile().getAbsolutePath().endsWith(extension))
                .forEach(p -> files.add(p.toString()));

        return files;
    }
}

Related

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