SpringBoot获取resources文件路径

2022-08-26 14:26:49

解决方案

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";
  • 作者:Ajekseg
  • 原文链接:https://blog.csdn.net/Ajekseg/article/details/123800232
    更新时间:2022-08-26 14:26:49