Java 如何使用模式匹配器列出目录中的文件
Java How to list files with directory with pattern matcher
文件结构如下:
root
-- [anything]
-- access.log
-- [anything]
-- access.log
路径:/root/*/access.log
谢谢。
DirectoryScanner scanner = new DirectoryScanner();
scanner.setIncludes(new String[]{"*/access.log"});
scanner.setBasedir(basePath);
scanner.scan();
String[] files = scanner.getIncludedFiles();
这是使用 org.apache.tools.ant.DirectoryScanner
的最简单的解决方案
文件结构如下:
root
-- [anything]
-- access.log
-- [anything]
-- access.log
路径:/root/*/access.log
谢谢。
DirectoryScanner scanner = new DirectoryScanner();
scanner.setIncludes(new String[]{"*/access.log"});
scanner.setBasedir(basePath);
scanner.scan();
String[] files = scanner.getIncludedFiles();
这是使用 org.apache.tools.ant.DirectoryScanner
的最简单的解决方案