Java Path File Extention nio getFilesList(Path directory, Set extensions)

Here you can find the source of getFilesList(Path directory, Set extensions)

Description

get Files List

License

Open Source License

Declaration

public static List<Path> getFilesList(Path directory, Set<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.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static List<Path> getFilesList(Path directory, Set<String> extensions) throws IOException {
        try (Stream<Path> stream = Files.list(directory)) {
            List<Path> list = stream.filter(path -> extensions.contains(getFileExtension(path)))
                    .collect(Collectors.toList());
            return list;
        }//from  w  w w  .ja va 2  s.co m
    }

    public static String getFileExtension(Path file) {
        String filename = file.getFileName().toString();
        return filename.substring(filename.lastIndexOf('.') + 1);
    }
}

Related

  1. getFileNameNoExtensionFromPath(String modulePath)
  2. getFilenameWithoutExtension(Path file)
  3. getFileNameWithoutExtension(Path path)
  4. getFileNameWithoutExtension(Path path)
  5. getFileNameWithoutExtension(String filePath)
  6. getFullNameWithoutExtension(Path f)
  7. getLeafName(Path path, boolean includeExtension)
  8. getListOfFilesByExtension(Path directoryPath, Set extensions)
  9. getPath(String outputDir, String qualifiedFilename, String fileextension)