Springboot项目创建文件中相对路径问题

时间:2020-02-27 20:40:31   收藏:0   阅读:1308

Springboot项目创建文件中相对路径问题

原代码:

String location = "./src/main/resources/UsersFiles/" + userId + "/";

File file = new File(location);

上面代码在没有tomcat环境下可以正常使用。当如果在tomcat之下。就会在所需的路径之前加上一个用户的/private路径。

技术图片

解决方法

指明项目路径:

System.getProperty("user.dir")

将上面改为

String location = System.getProperty("user.id") + "/src/main/resources/UsersFiles/" + userId + "/";

File file = new File(location);

此时成功新建文件。

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!