`
lpm528
  • 浏览: 81728 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

读取后缀为properties文件

    博客分类:
  • java
 
阅读更多

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics