标签:Java java specification System vendor version key 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
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。