如何从property文件中读取数据

来源:互联网 发布:js树状结构 编辑:程序博客网 时间:2024/03/29 22:11
private static Properties properties = new Properties();private String getPropertyValue(String key) {        loadCodeDip();        String value = (String)properties.get(key);          if(value.equals("")||null == value){               value="";          }else{              try {                  value=new String(value.getBytes("ISO8859_1"),"UTF-8");              } catch (UnsupportedEncodingException e) {                  e.printStackTrace();              }          }          return value;    }         private static void loadCodeDip(){        try {              properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties"));          } catch (IOException e) {              e.printStackTrace();        }      } 

调用:

String smsUrl = getPropertyValue("URL_PATH_FACTORY_LOGO");

property文件内容

URL_PATH_FACTORY_LOGO=http\://192.168.1.29\:8090/baseDataWebService/v1/writeFactoryPicture



0 0