java 得到项目的根目录的绝对路径
public static String getPath(HttpServletRequest request){
//取得项目路径 D:\apache-tomcat-8.0.32\webapps\volunteer
String sysPath = request.getServletContext().getRealPath("/");
sysPath = sysPath.replaceAll("\\\\", "/");
//转成数组
String[] str=sysPath.split("/");
StringBuffer sb =new StringBuffer();
//取到项目的根目录的绝对路径 D:\apache-tomcat-8.0.32\webapps
for(int i = 0; i < str.length-1;i++){
sb.append(str[i]+"/");
}
return sb.toString();
}