你可以试试一个叫做
maven-shared-utils
(检查类DirectoryScanner)。
或者你可以自己做:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
final String baseFolder = "folder1";
try {
Path pathBase = Paths.get(ClassLoader.getSystemResource(baseFolder).toURI());
Files.walk(pathBase.resolve("folder2/folder3"))
.filter(Files::isRegularFile)
.forEach(f -> System.out.println(pathBase.relativize(Paths.get(f.toUri()))));
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}}
此代码将为中的文件打印
src/main/resouces/folder1/folder2/folder3/*
:
文件夹2/文件夹3/文件2。json
文件夹2/文件夹3/文件3。千吨级
文件夹2/文件夹3/文件1。xml