public class Common {
private static Properties properties;
static {
try {
properties = new Properties();
InputStream in = Common.class.getClassLoader().getResourceAsStream("config.properties");
properties.load(in);
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getProperty(String Key) {
return properties.getProperty(Key);
}
}
package comat.common.property;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import comat.common.utils.CommonUtils;
public class PropertyConfig {
private static String default_config = "config.properties";
private static Properties mConfig;
static {
mConfig = new Properties();
try {
InputStream is = new BufferedInputStream(new FileInputStream(CommonUtils.getPath() + default_config));
mConfig.load(is);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static String getProperty(String key) {
return key != null ? mConfig.getProperty(key) != null ? mConfig.getProperty(key) : "" : "";
}
public static String getProperty(String key, String defaultValue) {
String value = mConfig.getProperty(key);
if (value == null)
return defaultValue;
return value;
}
public static boolean getBooleanProperty(String name, boolean defaultValue) {
String value = PropertyConfig.getProperty(name);
if (value == null)
return defaultValue;
return (new Boolean(value)).booleanValue();
}
public static int getIntProperty(String name) {
return getIntProperty(name, 0);
}
public static int getIntProperty(String name, int defaultValue) {
String value = PropertyConfig.getProperty(name);
if (value == null)
return defaultValue;
return (new Integer(value)).intValue();
}
public static int getIntValueByKey(String key) {
return Integer.parseInt(mConfig.getProperty(key));
}
public static String getStrValueByKey(String key) {
String value = null;
try {
value = new String(mConfig.getProperty(key).getBytes("ISO8859-1"), "utf-8");
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return value;
}
}
阅读(1583) | 评论(0) | 转发(0) |