解决方案

1、获取resources文件夹路径

File directory = new File("xxx/xxx/src/main/resources");
String reportPath = directory.getCanonicalPath();

xxx为你的项目内包的名称,File只会找到项目最外层地址;
这里需要注意,不能在xxx前面加/,否则只会找到顶层地址

我们的项目是从controller下获取resources下的文件:
在这里插入图片描述

	File directory = new File("src/main/resources");
    String reportPath = directory.getCanonicalPath();
    String resource =reportPath + "/static/template/resultTemplate.docx";
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐