Java资源加载相对路径和绝对路径

java加载资源的时候相对路径,就是相对本class资源文件的路径,比如:getResourceAsStream("../config.properties"),代表上一级目录下。

绝对路径就是在classPath的绝对路径下查找资源,比如:getResourceAsStream("/config.properties")就是在classpath+/config.properties位置查找。

其中classpath可以用户自己去查看

System.out.println(System.getProperty("sun.boot.class.path"));
System.out.println(System.getProperty("java.ext.dirs"));
System.out.println(System.getProperty("java.class.path"));

猜你喜欢

转载自takemind.iteye.com/blog/2342429