Wednesday, August 24, 2016

Consice way to collect sub-paths from a given path within Java 8

The following method represents a smart way of gathering subpaths within a path:

public static Path[] getDescendants(Path dir) {
try {
try (Stream<Path> entries = Files.walk(dir)) {
return entries.toArray(Path[]::new);
}
} catch (IOException ex) {
return new Path[0];
}
}

No comments:

Post a Comment