java读取配置文件

来源:互联网 发布:iphone照片mac air同步 编辑:程序博客网 时间:2024/04/27 20:50

参考:http://blog.sina.com.cn/s/blog_8af106960102v629.html


一般使用this.getClass().getResourceAsStream("/xxx.properties");适用于配置文件在src下的情况


也可以使用this.getClass().getClassLoader().getResource("").getPath();获取到当前类所在项目(服务器位置)的WEB-INF/classes/路径,比如:

String thispath = this.getClass().getClassLoader().getResource("").getPath();

System.out.println("hehehe=======================:"+thispath);

输出:hehehe=======================:/D:/work/selfServer/apache-tomcat-7.0.55/webapps/springMvc/WEB-INF/classes/

1 0
原创粉丝点击