Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1527846
  • 博文数量: 329
  • 博客积分: 2773
  • 博客等级: 少校
  • 技术积分: 4219
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 14:17
个人简介

淡定从容,宁静致远

文章分类

全部博文(329)

文章存档

2016年(4)

2015年(50)

2014年(68)

2013年(45)

2012年(162)

分类: Windows平台

2015-11-16 09:14:23

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;
}
}


阅读(1588) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~