- public static void main(String[] args) throws IOException {
- String glob = "glob:**.*";
- String path = "E:/pegasus";
- match(glob, path);
- }
- private static void match(String glob, String location) throws IOException {
- final PathMatcher pathMatcher = FileSystems.getDefault()
- .getPathMatcher(glob);
- Files.walkFileTree(Paths.get(location), new SimpleFileVisitor<Path>() {
- @Override
- public FileVisitResult visitFile(Path path,
- BasicFileAttributes attrs) throws IOException {
- if (pathMatcher.matches(path)) {
- System.out.println(path);
- }
- return FileVisitResult.CONTINUE;
- }
- });
- }
复制代码 |