zoukankan      html  css  js  c++  java
  • java 加载properties

        /**
         * 取得属性值,无值时返回默认值
         * @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) { }
            }
        }
  • 相关阅读:
    [bzoj4364] [IOI2014]wall砖墙
    [bzoj3064] [Tyvj 1518] CPU监控
    [bzoj3434] [WC2014]时空穿梭
    ASP.NET
    ASP.NET
    ASP.NET
    ASP.NET
    ASP.NET
    ASP.NET
    MSSQL
  • 原文地址:https://www.cnblogs.com/whm-blog/p/10436512.html
Copyright © 2011-2022 走看看