web(获取路径的方法)

 String path = this.getServletContext().getRealPath("/");
 String path2 = this.getClass().getClassLoader().getResource("/").getPath();
 String path3 = Thread.currentThread().getContextClassLoader().getResource("/").getPath();

输出结果如下:

path:E:apache-tomcat-8.5.23-windows-x64apache-tomcat-8.5.23webapps
path2:/E:/apache-tomcat-8.5.23-windows-x64/apache-tomcat-8.5.23/webapps/WEB-INF/classes/
path3:/E:/apache-tomcat-8.5.23-windows-x64/apache-tomcat-8.5.23/webapps/WEB-INF/classes/

原文地址:https://www.cnblogs.com/beibidewomen/p/7922853.html