java读取配置文件

参考: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/

你可能感兴趣的:(java读取配置文件)