ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 设置系统属性 * jvm参数,通常用于设置系统级全局变量值,如配置文件路径,保证该属性在程序中任何地方都可访问; ``` -Duser.displayName=kimi ``` 注意: 1)需要设置的是JVM参数而不是program参数; 2)使用此参数的参数优先级最高,会覆盖项目中配置的此项; 3)如果value中有空格,则需要用双引号将该值括起来,如:-Dname="kafka mq"; * 系统设置 ``` System.setProperty("use.workspace", "/stsspace"); properties.put("use.workspace", "robert"); ``` ### 获取系统属性 * System.getenv()获取系统属性 ``` Map<String, String> env = System.getenv(); { "PATH": "/usr/bin:/bin:/usr/sbin:/sbin", "SHELL": "/bin/bash", "JAVA_MAIN_CLASS_16868": "charpter01.Appliction", "APP_ICON_7487": "../Resources/sts.icns", "USER": "Robert", "TMPDIR": "/var/folders/j9/3zh_xlcn2xd8vcjwl8tdpkdw0000gn/T/", "SSH_AUTH_SOCK": "/private/tmp/com.apple.launchd.vSDQaW0NNQ/Listeners", "XPC_FLAGS": "0x0", "__CF_USER_TEXT_ENCODING": "0x1F5:0x19:0x34", "Apple_PubSub_Socket_Render": "/private/tmp/com.apple.launchd.lxCKCDfnjG/Render", "LOGNAME": "Robert", "XPC_SERVICE_NAME": "org.springsource.sts.ide.37052", "HOME": "/Users/Robert" } ``` * System.getProperties()获取系统属性 ``` Properties properties = System.getProperties(); properties.put("use.workspace", "robert"); //设置系统属性 ```