首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

读取后缀替properties文件

2012-10-20 
读取后缀为properties文件public class GetCfg {?private static Properties pro null?private static

读取后缀为properties文件

public class GetCfg {
?private static Properties pro = null;
?private static GetCfg getcfg = new GetCfg();? //调用方法之前先初始化static变量
?private GetCfg()
?{
??pro = new Properties();????//new Properties对象
??try {
???pro.load(this.getClass().getClassLoader().getResourceAsStream("conf.properties"));?//读取加载conf.properties文件
??} catch (IOException e) {
?????e.printStackTrace();
??}
?}
?
?public static String getValue(String key)
?{
??String v = pro.getProperty(key.trim()).trim();???? //通过变量名或得具体的值
??return (null == v)? "" : v.trim();
?}
?public static String getDefaultValue(String key ,String defaultStr)
?{
??return pro.getProperty(key.trim(), defaultStr).trim();
?}
}

热点排行