龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

java 获取项目文件路径实现方法

时间:2014-06-16 02:28来源:网络整理 作者:网络 点击:
分享到:
以下是对java中获取项目文件路径的实现方法进行了介绍,需要的朋友可以过来参考下

this.getClass().getResource("/").getPath().substring(1)获得路径为E:/myeclipse/test/WebRoot/WEB-INF/classes/,即主目录。

this.getClass().getResource("").getPath().substring(1)获得路径为E:/myeclipse/test/WebRoot/WEB-INF/classes/net/hncu/db/,即本文件的相对路径。

this.getClass().getResource(".").getPath().substring(1)和this.getClass().getResource("").getPath().substring(1)效果一样

精彩图集

赞助商链接