springboot 部署到tomcat,获取根路径问题。空格变为%20

String path = ResourceUtils.getURL("classpath:").getPath()+"static/upload";
System.out.println(path);
//本地开发输出/C:/Program Files/Apache Software Foundation/Tomcat 9.0/webapps/xxx/WEB-INF/classes/static/upload
//部署到服务器输出/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%209.0/webapps/xxx/WEB-INF/classes/static/upload path = URLDecoder.decode(path,"utf-8");//处理空格转化为%20 System.out.println(path);
//本地开发输出/C:/Program Files/Apache Software Foundation/Tomcat 9.0/webapps/xxx/WEB-INF/classes/static/upload //部署到服务器输出/C:/Program Files/Apache Software Foundation/Tomcat 9.0/webapps/xxx/WEB-INF/classes/static/upload

 

posted @ 2019-05-17 10:18  晨风啊  阅读(2825)  评论(0编辑  收藏  举报