Code: Select all
Path path = Paths.get("plants");
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**.txt");
try (DirectoryStream<Path> usingString = Files.newDirectoryStream(path, "*.txt");
DirectoryStream<Path> usingMatcher = Files.newDirectoryStream(path, matcher::matches)) {
usingMatcher.forEach(System.out::println);
System.out.println("---------------------------------------");
usingString.forEach(System.out::println);
}