package com.gt.agent.util;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.apache.commons.lang.StringUtils;
/**
* 读取配置文件
* ClassName: ResourceUtil
* @Description: TODO
* @author LiuSiGuang
* @date 2017年7月19日 下午1:19:44
*/
public class ResourceUtil {
private static final String OWN_CONFIG_FILE_NAME = "config";
private static ResourceBundle properties;
/**
* Get the value of a string property.
* @param property The property to retrieve
* @return The property value
* @throws MissingResourceException In case the message with the property name could not be found.
*/
public synchronized static String getPropertyValue(String property, String defaultValue) throws MissingResourceException {
if (properties == null) {
properties = ResourceBundle.getBundle(OWN_CONFIG_FILE_NAME);
}
String propertyValue = properties.getString(property);
if (StringUtils.isNotEmpty(propertyValue)) {
return propertyValue;
} else {
return defaultValue;
}
}
public synchronized static String getPropertyValue(String property){
if (properties == null) {
properties = ResourceBundle.getBundle(OWN_CONFIG_FILE_NAME);
}
return properties.getString(property);
}
}
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.apache.commons.lang.StringUtils;
/**
* 读取配置文件
* ClassName: ResourceUtil
* @Description: TODO
* @author LiuSiGuang
* @date 2017年7月19日 下午1:19:44
*/
public class ResourceUtil {
private static final String OWN_CONFIG_FILE_NAME = "config";
private static ResourceBundle properties;
/**
* Get the value of a string property.
* @param property The property to retrieve
* @return The property value
* @throws MissingResourceException In case the message with the property name could not be found.
*/
public synchronized static String getPropertyValue(String property, String defaultValue) throws MissingResourceException {
if (properties == null) {
properties = ResourceBundle.getBundle(OWN_CONFIG_FILE_NAME);
}
String propertyValue = properties.getString(property);
if (StringUtils.isNotEmpty(propertyValue)) {
return propertyValue;
} else {
return defaultValue;
}
}
public synchronized static String getPropertyValue(String property){
if (properties == null) {
properties = ResourceBundle.getBundle(OWN_CONFIG_FILE_NAME);
}
return properties.getString(property);
}
}