在Java中,可以使用System.getProperty("user.dir")
来获取当前项目的工作目录路径。这个路径通常是项目部署路径的父级目录。
另外,如果你想获取项目部署路径的话,可以使用以下方法之一:
-
使用
ClassLoader
来获取项目的根路径:String rootPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
-
使用
ServletContex
对象来获取项目的根路径(只适用于Web项目):String rootPath = getServletContext().getRealPath("/");