功能: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 }