key-value customized value read java .properties configuration file

  / ** 
     * .properties reads the configuration file 
     * @param path propertiesUrl configuration file 
     * @return configuration file key-value value
      * / 
    public  static the Map <String, String> getProperties (String propertiesUrl) { 
        the Map <String, String > The resultMap = new new the HashMap <String, String> (); 
        the properties prop = new new the properties ();
         the try {
             // read the attribute file a.properties 
            the InputStream in = new new BufferedInputStream ( new new the FileInputStream (propertiesUrl));
            // 加载属性列表
            prop.load(in);
            Iterator<String> it = prop.stringPropertyNames().iterator();
            while (it.hasNext()) {
                String key = it.next();
                resultMap.put(key, prop.getProperty(key));
                System.out.println("key: "+key+",      value: "+prop.getProperty(key));
            }
            in.close();
        } catch (Exception e) {
            System.out.println(e);
        }
        return resultMap;
    }

 

Guess you like

Origin www.cnblogs.com/52KT9/p/12527038.html