其他分享
首页 > 其他分享> > System.getProperty方法

System.getProperty方法

作者:互联网

Demo

private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
private static String zookeeperPort = System.getProperty("zookeeper.port", "2181");

使用System.getProperty获得属性,如果未获得指定key的值,使用后面的作为default value。

 

System.getProperty方法支持以下属性:

    public static String getProperty(String key) {
        checkKey(key);
        SecurityManager sm = getSecurityManager();
        if (sm != null) {
            sm.checkPropertyAccess(key);
        }

        return props.getProperty(key);
    }

  

 checkKey(String key)

private static void checkKey(String key) {
        if (key == null) {
            throw new NullPointerException("key can't be null");
        }
        if (key.equals("")) {
            throw new IllegalArgumentException("key can't be empty");
        }
    }
props.getProperty(key)
    public String getProperty(String key) {
        Object oval = map.get(key);
        String sval = (oval instanceof String) ? (String)oval : null;
        Properties defaults;
        return ((sval == null) && ((defaults = this.defaults) != null)) ? defaults.getProperty(key) : sval;
    }

 

标签:Java,java,specification,System,vendor,version,key,getProperty,方法
来源: https://www.cnblogs.com/use-D/p/16645121.html