码迷,mamicode.com
首页 > 其他好文 > 详细

工程中properties文件处理方法类

时间:2016-06-05 15:20:48      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:

功能:properties文件加载、取得key对应的值

 1 import java.util.ResourceBundle;
 2 
 3 /**
 4  * 工程中properties文件处理方法类
 5  */
 6 public class ConfigHolder {
 7     private static ResourceBundle bundle;
 8     
 9     /**
10      * 加载properties文件
11      */
12     private static void loadConfig() {
13         if(bundle == null) {
14             // 在class下有config.properties文件,如果在某包下,则如:ort.config
15             bundle = ResourceBundle.getBundle("config");
16         }
17     }
18     
19     /**
20      * 取得properties文件中指定key的值
21      * @param key
22      * @return
23      */
24     public static String getValue(String key) {
25         loadConfig();
26         return bundle.getString(key);
27     }    
28 }

 

工程中properties文件处理方法类

标签:

原文地址:http://www.cnblogs.com/Mr-kevin/p/5560723.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!