java读取properties文件的内容

 

获得properties文件中某个key对应着的value

// 路径名称 + properties的名称,不要“properties”
private static final String BUNDLE_NAME = "com.xxx.cs.mm.service.messages";

private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

public static String getString(String key) {
    try {
        return RESOURCE_BUNDLE.getString(key);
    } catch (MissingResourceException e) {
         return '!' + key + '!';
    }
}

 

Format其中的值

MessageFormat.format(RESOURCE_BUNDLE.getString("SomeKey"), new Object[] { "1", "2" }));

 

posted @ 2015-03-27 15:49  VoctrALs  阅读(139)  评论(0编辑  收藏  举报