public class Path {
/**
* @author snow
* @description 得到项目的根目录的绝对路径
*/
public static String getPath(HttpServletRequest request){
String path = request.getSession().getServletContext().getRealPath("/"));//表示到项目的根目录下,要是想到目录下的子文件夹,修改"/"即可
path = path.replaceAll("\\\\", "/");
return path;
}
}
可以单独作为一个工具类,要用的时候调用就好了