import java.nio.file.*; import java.util.*; public class GlobExample { public static void main(String[] args) throws Exception { PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.txt"); List<String> matchedFiles = new ArrayList<>(); Files.walkFileTree(Paths.get("path/to/folder"), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (matcher.matches(file.getFileName())) { matchedFiles.add(file.toString()); } return FileVisitResult.CONTINUE; } }); for (String file : matchedFiles) { System.out.println(file); } } }


上一篇:
下一篇:
切换中文