您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

如何在Java 9的JShell中获取系统属性?

2026/1/7 8:13:16发布14次查看
jshell is a repl (read-evaluate-print-loop) tool used to execute simple statements, evaluates it, and displays the result without a main() method. we can start it by simply type jshell in command-line prompt.
we need to get the system properties by using system.getproperty() and system.getproperties() methods.
in the below code snippet, we can able to display the system properties in the jshell tool by using static method property() of system class.
snippet-1jshell> system.getproperty("java.class.path")$1 ==> "c:\program files\java\jdk-9.0.4\lib;c:\json-jars\json.jar;.;c:\json-jars\json-simple.jar;.;c:\json-jars\gson.jar;.;c:\json-jars\commons-io.jar;.;c:\json-jars\jackson-core.jar;.;c:\json-jars\jackson-databind.jar;.;c:\json-jars\jackson-annotations.jar;.;c:\json jars\flexjson.jar;.;c:\json-jars\jackson-dataformat-xml.jar;.;c:\json-jars\stax2-api.jar;.;c:\json-jars\jackson-dataformat-csv.jar;.;c:\json-jars\javax.json.jar;.;c:\json jars\javax.json-api.jar;.;c:\json-jars\jackson-module-jsonschema.jar;.;c:\json-jars\json-lib.jar;.;c:\json-jars\commons-lang.jar;.;c:\json-jars\commons-logging.jar;.;"
在下面的代码片段中,我们必须使用扩展了hashtable的“properties”对象。因此,可以通过在jshell工具中使用“system.getproperties().foreach((k, v)”来列出所有属性作为键/值对.
snippet-2jshell> system.getproperties().foreach((k, v) -> { system.out.printf("%s: %s\n", k, v); })sun.desktop: windowsawt.toolkit: sun.awt.windows.wtoolkitjava.specification.version: 9file.encoding.pkg: sun.iosun.cpu.isalist: amd64sun.jnu.encoding: cp1252java.class.path: c:\program files\java\jdk-9.0.4\lib;c:\json jars\json.jar;.;c:\json jars\json-simple.jar;.;c:\json jars\gson.jar;.;c:\json jars\commons-io.jar;.;c:\json jars\jackson-core.jar;.;c:\json jars\jackson-databind.jar;.;c:\json jars\jackson-annotations.jar;.;c:\json jars\flexjson.jar;.;c:\json jars\jackson-dataformat-xml.jar;.;c:\json jars\stax2-api.jar;.;c:\json jars\jackson-dataformat-csv.jar;.;c:\json jars\javax.json.jar;.;c:\json jars\javax.json-api.jar;.;c:\json jars\jackson-module-jsonschema.jar;.;c:\json jars\json-lib.jar;.;c:\json jars\commons-lang.jar;.;c:\json jars\commons-logging.jar;.;java.vm.vendor: oracle corporationsun.arch.data.model: 64user.variant:java.vendor.url: http://java.oracle.com/user.timezone:os.name: windows 8.1java.vm.specification.version: 9sun.java.launcher: sun_standarduser.country: ussun.boot.library.path: c:\program files\java\jdk-9.0.4\binsun.java.command: jdk.jshell.execution.remoteexecutioncontrol 54984jdk.debug: releasesun.cpu.endian: littleuser.home: c:\users\useruser.language: enjava.specification.vendor: oracle corporationjava.home: c:\program files\java\jdk-9.0.4file.separator: \java.vm.compressedoopsmode: 32-bitline.separator:java.vm.specification.vendor: oracle corporationjava.specification.name: java platform api specificationjava.awt.graphicsenv: sun.awt.win32graphicsenvironmentuser.script:sun.management.compiler: hotspot 64-bit tiered compilersjava.runtime.version: 9.0.4+11user.name: userpath.separator: ;os.version: 6.3java.runtime.name: java(tm) se runtime environmentfile.encoding: cp1252java.vm.name: java hotspot(tm) 64-bit server vmjava.vendor.url.bug: http://bugreport.java.com/bugreport/java.io.tmpdir: c:\users\user\appdata\local\temp\java.version: 9.0.4user.dir: c:\users\user\desktop\java 9 qnaos.arch: amd64java.vm.specification.name: java virtual machine specificationjava.awt.printerjob: sun.awt.windows.wprinterjobsun.os.patch.level:java.library.path: c:\program files\java\jdk-9.0.4\bin;c:\windows\sun\java\bin;c:\windows\system32;c:\windows;c:\program files\java\jdk-9.0.4\bin;.;;.java.vm.info: mixed modejava.vendor: oracle corporationjava.vm.version: 9.0.4+11sun.io.unicode.encoding: unicodelittlejava.class.version: 53.0
以上就是如何在java 9的jshell中获取系统属性?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product