读书人

怎么在java web项目后端项目中获取路径

发布时间: 2012-08-22 09:50:34 作者: rapoo

如何在java web项目后端项目中获取路径

1、获取类文件下的绝对路径

youClass.class.getResource("/").toString().replaceAll("file:/", "")

?

2、获取项目路径

getServletContext().getRealPath("/");

?

?3、获取类文件路径

this.getClass().getClassLoader().getResource("/").getPath();

?

4、获取项目路径

request.getContextPath();

?

5、获取项目路径
System.getProperty("user.dir")

?

6、获取顶级路径

new File("/").getAbsolutePath()

?

7、获取当前类路径

ClassLoader.getSystemResource("")

?

8、获取当前类路径

Thread.currentThread().getContextClassLoader().getResource("")

读书人网 >Web前端

热点推荐