获取Java中的默认系统属性
要返回Java中的所有默认系统属性,请首先使用System.getProperties()方法。
java.util.Properties prop = System.getProperties();
之后,使用list()
方法列出所有这些方法。
prop.list(System.out);
示例
public class Demo { public static void main(String[] args) { java.util.Properties prop = System.getProperties(); System.out.println("这是属性:"); prop.list(System.out); } }
输出结果
这是属性: java.runtime.name=OpenJDK Runtime Environment sun.boot.library.path=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... java.vm.version=25.141-b16 java.vm.vendor=Oracle Corporation java.vendor.url=http://java.oracle.com/ path.separator=: java.vm.name=OpenJDK 64-Bit Server VM file.encoding.pkg=sun.io user.country=US sun.java.launcher=SUN_STANDARD sun.os.patch.level=unknown java.vm.specification.name=Java Virtual Machine Specification user.dir=/home/cg/root/3757524 java.runtime.version=1.8.0_141-b16 java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment java.endorsed.dirs=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... os.arch=amd64 java.io.tmpdir=/tmp line.separator= java.vm.specification.vendor=Oracle Corporation os.name=Linux sun.jnu.encoding=UTF-8 java.library.path=/home/cg/root/GNUstep/Library/Librari... java.specification.name=Java Platform API Specification java.class.version=52.0 sun.management.compiler=HotSpot 64-Bit Tiered Compilers os.version=3.10.0-862.9.1.el7.x86_64 user.home=? user.timezone= java.awt.printerjob=sun.print.PSPrinterJob file.encoding=UTF-8 java.specification.version=1.8 user.name=? java.class.path=/home/cg/root/GNUstep/Library/Librari... java.vm.specification.version=1.8 sun.arch.data.model=64 java.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... sun.java.command=Demo java.specification.vendor=Oracle Corporation user.language=en awt.toolkit=sun.awt.X11.XToolkit java.vm.info=mixed mode java.version=1.8.0_141 java.ext.dirs=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... sun.boot.class.path=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0... java.vendor=Oracle Corporation file.separator=/ java.vendor.url.bug=http://bugreport.sun.com/bugreport/ sun.cpu.endian=little sun.io.unicode.encoding=UnicodeLittle sun.cpu.isalist=