版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Fouse_/article/details/79579569
获取web项目下文件夹或者文件的绝对路径
WebApplicationContext webApplicationContext = ContextLoader
.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext
.getServletContext();
// 得到文件夹绝对路径
String relpath = servletContext.getRealPath("/xml");
System.out.println(relpath);