Web项目获取项目“相对路径”,以获取特定资源

版权声明:本博文仅供学习、参考、技术讨论,版权归笔者/译者所有。 https://blog.csdn.net/qq_38025219/article/details/83087528

//类加载根路径
String classPath = this.getClass().getResource("/").getPath();

//类加载根路径
URL xmlPath = this.getClass().getClassLoader().getResource("");

//类所在工程根路径
String proClassPath = this.getClass().getResource("").getPath();

//项目服务器脚本文件路径
File directory = new File("");// 参数为空
String proRootPath = directory.getCanonicalPath();

//项目服务器脚本文件路径
String proPath = System.getProperty(“user.dir”);

// 获取所有的类路径 包括jar包的路径
String allClassPath = System.getProperty(“java.class.path”);

//项目部署的路径
String path = request.getSession().getServletContext().getRealPath("/");

猜你喜欢

转载自blog.csdn.net/qq_38025219/article/details/83087528