System.getProperty方法
2022/9/1 6:53:06
本文主要是介绍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; }
这篇关于System.getProperty方法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?
- 2024-05-09企业src漏洞挖掘-有意思的命令执行