spring mvc 动态读配置文件

来源:互联网 发布:淘宝代理免费加盟 编辑:程序博客网 时间:2024/06/06 03:16
package com.autohome.common;import java.io.*;import java.util.Properties;public class PropertyUtil {    private static Properties props;    private static  void loadProps() {        props = new Properties();        InputStream in = null;        try {            in = PropertyUtil.class.getClassLoader().getResourceAsStream("Config.properties");            props.load(in);        } catch (FileNotFoundException e) {        } catch (IOException e) {        } finally {            try {                if (null != in) {                    in.close();                }            } catch (IOException e) {            }        }    }    public static String getProperty(String key) {        if (null == props) {            loadProps();        }        return props.getProperty(key);    }    public static String getProperty(String key, String defaultValue) {        if (null == props) {            loadProps();        }        return props.getProperty(key, defaultValue);    }}