话不多说,直接上代码:
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String path=request.getSession().getServletContext().getRealPath("/WEB-INF/conf/custom.properties");
/WEB-INF/conf/custom.properties 这是相对路径,写上去就可以获取custom.properties的绝对路径
本文介绍了一种通过Java代码获取Web应用程序中custom.properties文件绝对路径的方法。利用HttpServletRequest对象和getServletContext().getRealPath方法,可以方便地从相对路径转换为绝对路径。
1074

被折叠的 条评论
为什么被折叠?



