码迷,mamicode.com
首页 > 编程语言 > 详细

java 加载properties

时间:2019-02-26 13:22:04      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:属性   man   cte   tcl   reading   cat   erro   val   默认值   

    /**
     * 取得属性值,无值时返回默认值
     * @param name String 属性名称
     * @param defaultValue String 属性名称
     * @return String 属性值
     */
    protected String getProp(String name,String defaultValue) {
          if (properties == null) {
            synchronized(propertiesLock) {
                if (properties == null) {
                    loadProps();
                }
            }
        }
        String property = properties.getProperty(name);
        if (property == null) {
            return defaultValue;
        }
        else {
            return property.trim();
        }
    }

 

/**
     * 加载属性
     */
    private void loadProps() {
        properties = new Properties();
        InputStream in = null;
        try {
            in = getClass().getResourceAsStream(resourceURI);
            properties.load(in);
        }
        catch (Exception e) {
            System.err.println("Error reading Application properties in PropertyManager.loadProps() " + e);
            e.printStackTrace();
        }
        finally {
            try {
                in.close();
            } catch (Exception e) { }
        }
    }

 

java 加载properties

标签:属性   man   cte   tcl   reading   cat   erro   val   默认值   

原文地址:https://www.cnblogs.com/whm-blog/p/10436512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!