首页 > 其他 > 详细

读取properties属性文件

时间:2016-06-21 18:58:40      阅读:176      评论:0      收藏:0      [点我收藏+]

1、通过类加载器加载

InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("Chapter8/test.properties"); 
Properties p = new Properties();  
p.load(inputStream );

2、通过文件系统加载

InputStream inputStream = new FileInputStream("Chapter8/test.properties"); 

以下是获取当前工程路径的方法:

public static void main(String[] args) {
	// TODO Auto-generated method stub

	path[0] = Thread.currentThread().getContextClassLoader()
				.getResource("Chapter8/test.properties").getPath();
	path[1] = this.getClass().getClassLoader()
				.getResource("Chapter8/test.properties").getPath();
	path[2] = ClassLoader.getSystemResource("Chapter8/test.properties")
				.getPath();
}

  

读取properties属性文件

原文:http://www.cnblogs.com/SaraMoring/p/5604635.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!