当前位置:编程学习 > JAVA >>

java读取属性文件

/**
  * nc
  * 读取属性文件
  * @param path
  * @param Key
  * @return
  */
 public static String getPropertiesValue(String path,String Key){
  path="../classes/resource/jdbc-config/jdbc.properties";
  String _value = Key;
  try {
   URL configs = Thread.currentThread().getContextClassLoader().getResource(path);//"../classes/resource/jdbc-config/jdbc.properties"      
   InputStream is = configs.openStream();
   Properties pro = new Properties();
   pro.load(is);
   _value = pro.getProperty(Key);
  } catch (Exception e) {
   e.fillInStackTrace(); 
  }
  if(StringUtils.isBlank(_value)){
   _value="";
  }
  return _value;
 }
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,