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方法支持以下属性:
- java.version:Java Runtime Environment version, which may be interpreted as a Runtime.Version
- java.version.date:Java Runtime Environment version date, in ISO-8601 YYYY-MM-DD format, which may be interpreted as a java.time.LocalDate
- java.vendor:Java Runtime Environment vendor
- java.vendor.url:Java vendor URL
- java.vendor.version:Java vendor version
- java.home:Java installation directory
- java.vm.specification.version:Java Virtual Machine specification version, whose value is the feature element of the runtime version
- java.vm.specification.vendor:Java Virtual Machine specification vendor
- java.vm.specification.name:Java Virtual Machine specification name
- java.vm.version:Java Virtual Machine implementation version which may be interpreted as a Runtime.Version
- java.vm.vendor:Java Virtual Machine implementation vendor
- java.vm.name:Java Virtual Machine implementation name
- java.specification.version:Java Runtime Environment specification version, whose value is the feature element of the runtime version
- java.specification.vendor:Java Runtime Environment specification vendor
- java.specification.name:Java Runtime Environment specification name
- java.class.version:Java class format version number
- java.class.path:Java class path (refer to ClassLoader.getSystemClassLoader() for details)
- java.library.path:List of paths to search when loading libraries
- java.io.tmpdir:Default temp file path
- java.compiler:Name of JIT compiler to use
- os.name:Operating system name
- os.arch:Operating system architecture
- os.version:Operating system version
- file.separator:File separator ("/" on UNIX)
- path.separator:Path separator (":" on UNIX)
- line.separator:Line separator ("\n" on UNIX)
- user.name:User's account name
- user.home:User's home directory
- user.dir:User's current working directory
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