Package br.com.mystudies.niotwo

Source Code of br.com.mystudies.niotwo.FilesFilter

package br.com.mystudies.niotwo;

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

public class FilesFilter {

  public List<Path> getFiles(String path, FileExtension fileExtension) {

    FileSystem fileSystem = FileSystems.getDefault();

    List<Path> files = new ArrayList<>() ;

    try(DirectoryStream<Path> directoryStream =
        Files.newDirectoryStream( fileSystem.getPath(path), "*" + fileExtension.getExtension())) {

      for (Path file : directoryStream) {
        files.add(file);
      }

    } catch (IOException exception) {
      return null;
    }

    return files;

  }
}
TOP

Related Classes of br.com.mystudies.niotwo.FilesFilter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.