Listing the Entire Content of a directory as links, files, subdirectories, and hidden files - Java File Path IO

Java examples for File Path IO:Directory Content

Description

Listing the Entire Content of a directory as links, files, subdirectories, and hidden files

Demo Code

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) {
    Path path = Paths.get("C:/folder1/folder2/folder4");

    // no filter applied
    System.out.println("\nNo filter applied:");
    try (DirectoryStream<Path> ds = Files.newDirectoryStream(path)) {
      for (Path file : ds) {
        System.out.println(file.getFileName());
      }/*  w  w w  . jav a2  s  . c  o  m*/
    } catch (IOException e) {
      System.err.println(e);
    }

  }
}

Result


Related Tutorials