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目录