您的位置:首页 > 编程语言 > Java开发

java读取配置文件

2016-04-26 16:29 183 查看
参考: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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: