0
点赞
收藏
分享

微信扫一扫

SpringBoot获取resources文件路径

小北的爹 2022-03-30 阅读 83
java后端

解决方案

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";
举报

相关推荐

0 条评论