java获取目录路径_java获取目录路径,

1、System.out.println(System.getProperty("user.dir"));

输出:E:\Program Files\myeclipse10\workplace\Test ,即项目路径

2、System.out.println(System.getProperty("java.class.path"));

输出:E:\Program Files\myeclipse10\workplace\Test\bin;E:\Program Files\myeclipse10\workplace\Test\lib\antlr-2.7.6.jar;E:\Program Files\myeclipse10\workplace\Test\lib\commons-collections-3.1.jar;E:\Program Files\myeclipse10\workplace\Test\lib\dom4j-1.6.1.jar;E:\Program Files\myeclipse10\workplace\Test\lib\hibernate3.jar;E:\Program Files\myeclipse10\workplace\Test\lib\sqljdbc4.jar

项目的bin目录,还有各种引用的jar包的路径

3、System.out.println(this.getClass().getResource(""));

输出:file:/E:/Program%20Files/myeclipse10/workplace/Test/bin/com/test/hibernate/,路径具体到了该类所在的包

4、System.out.println(this.getClass().getResource("/"));

输出:file:/E:/Program%20Files/myeclipse10/workplace/Test/bin/,bin目录但是没有到具体的包

5、System.out.println(this.getClass().getClassLoader().getResource("").getPath());

输出:/E:/Program%20Files/myeclipse10/workplace/Test/bin/,类加载路径

6、System.out.println(this.getClass().getResource("").getPath());

输出:/E:/Program%20Files/myeclipse10/workplace/Test/bin/com/test/hibernate/

7、System.out.println(this.getClass().getClassLoader().getResource(""));

输出:file:/E:/Program%20Files/myeclipse10/workplace/Test/bin/

pro.load(this.getClass().getClassLoader().getResourceAsStream("my/aa.properties"));

其中my/aa.properties是相对于src目录的路径,也是bin下的路径。

getClassLoader得到的是src目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值