有没有办法在java中检索url的绝对路径(http:// localhost:8080/myApp).方案是,我需要连接到位于tomcat服务器的csv文件.如果我输入绝对路径,该语句很有效,但是有一个解决方案可以使用getAbsolutePath()检索url的路径.抱歉,如果我错了.
Connection conn = DriverManager(getConnection("jdbc:relique:csv:/home/apache-tomcat-6.0.26/webapps/myApp/"))
Run Code Online (Sandbox Code Playgroud)
提前致谢.
Joa*_*uer 10
你可以使用ServletContext.getRealPath(),它完全符合你的要求.
需要注意的是它并没有一定适用于所有情况.例如,如果您的Tomcat配置为部署.war文件而不解压缩,那么这将返回null.
| 归档时间: |
|
| 查看次数: |
14487 次 |
| 最近记录: |