import java.nio.file.*; public class GlobExample { public static void main(String[] args) throws Exception { FileSystem fs = FileSystems.getDefault(); PathMatcher matcher = fs.getPathMatcher("glob:*.txt"); Path dir = Paths.get("C:/data"); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path file : stream) { if (matcher.matches(file.getFileName())) { System.out.println(file); } } } } }


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