List all files in a directory

    0

    7

    Java Public Recipes

    List all the files in a directory using Java 8 methods

    import java.io.IOException;
    import java.nio.*;
    import java.util.stream.Stream;
    
    try {
      Stream<Path> files = Files.walk(Paths.get("/path/to/directory"));
      // Do something with the files such as files.forEach(System.out::println);
      files.close();
    } catch (IOException e) {
      // directory not found or invalid permissions
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.