BAEL-4755: Add Files.list example (#10356)

This commit is contained in:
kwoyke
2020-12-30 12:39:45 +01:00
committed by GitHub
parent a357178525
commit ed330c5c0d
2 changed files with 18 additions and 2 deletions

View File

@@ -24,9 +24,20 @@ public class ListFiles {
.collect(Collectors.toSet());
}
public Set<String> listFilesUsingFilesList(String dir) throws IOException {
try (Stream<Path> stream = Files.list(Paths.get(dir))) {
return stream
.filter(file -> !Files.isDirectory(file))
.map(Path::getFileName)
.map(Path::toString)
.collect(Collectors.toSet());
}
}
public Set<String> listFilesUsingFileWalk(String dir, int depth) throws IOException {
try (Stream<Path> stream = Files.walk(Paths.get(dir), depth)) {
return stream.filter(file -> !Files.isDirectory(file))
return stream
.filter(file -> !Files.isDirectory(file))
.map(Path::getFileName)
.map(Path::toString)
.collect(Collectors.toSet());