September 2019
Intermediate to advanced
816 pages
18h 47m
English
Starting with JDK 8, the Files class has been enriched with two walk() methods. These methods return a Stream that is lazily populated with Path. It does this by walking the file tree that's rooted at a given starting file using the given maximum depth and options:
public static Stream<Path> walk( Path start, FileVisitOption...options) throws IOExceptionpublic static Stream<Path> walk( Path start, int maxDepth, FileVisitOption...options) throws IOException
For example, let's display all the paths from D:/learning that start with D:/learning/books/cdi:
Path directory = Paths.get("D:/learning");Stream<Path> streamOfPath = Files.walk( directory, FileVisitOption.FOLLOW_LINKS);streamOfPath.filter(e -> e.startsWith("D:/learning/books/cdi")) ...Read now
Unlock full access