首页 > Windows开发 > 详细

使用J2SE API读取Properties文件的六种方

时间:2014-01-26 14:30:49      阅读:477      评论:0      收藏:0      [点我收藏+]

 

1.使用Java.util.Properties类的load()方法 

示例:

InputStream in = lnew BufferedInputStream(new FileInputStream(name));  

Properties p = new Properties(); 

p.load(in); 

2.使用java.util.ResourceBundle类的getBundle()方法

示例

ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());  

3.使用java.util.PropertyResourceBundle类的构造函数

示例:

InputStream in = new BufferedInputStream(new FileInputStream(name)); 

ResourceBundle rb = new PropertyResourceBundle(in);  

4.使用class变量的getResourceAsStream()方法

示例:

InputStream in = JProperties.class.getResourceAsStream(name); 

Properties p = new Properties(); 

p.load(in);  

5.

使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法

示例:

 InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name); 

 Properties p = new Properties(); 

 p.load(in); 

6.使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法

 示例:

InputStream in = ClassLoader.getSystemResourceAsStream(name); 

 Properties p = new Properties(); 

 p.load(in); 

 

使用J2SE API读取Properties文件的六种方

原文:http://www.cnblogs.com/Wen-yu-jing/p/3533708.html

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