Java获取properties配置文件信息

调用方法:String url = PropertiesUtil.getProperty("url");

public class PropertiesUtil {

    public static Properties property;
    static {
        property = new Properties();
        InputStream in = PropertiesUtil.class.getResourceAsStream("/init.properties");
        try {
            property.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    
    public static String getProperty(String key) {
        return property.getProperty(key);
    }
}

 

posted @ 2015-11-25 09:56  空还是空  阅读(284)  评论(0编辑  收藏  举报