In this example, we can use the getProperties() method in the System class to get the key-value pairs for the System properties, as shown below.
Source Code
package com.beginner.examples;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class GetProperty {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//Gets the key-value pair for the system properties
Properties pro=System.getProperties();
//Gets the set of relationships for key-value pairs
Set<Map.Entry> relation=pro.entrySet();
Iterator<Map.Entry> it=relation.iterator();
System.out.println("Property-------Value");
while(it.hasNext())
{
Map.Entry r=it.next();
System.out.println(r.getKey()+"-------"+r.getValue());
}
}
}
Output:
Property-------Value
java.runtime.name-------Java(TM) SE Runtime Environment
sun.boot.library.path-------D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jrebin
java.vm.version-------11.3-b02
java.vm.vendor-------Sun Microsystems Inc.
java.vendor.url-------http://java.sun.com/
path.separator-------;
java.vm.name-------Java HotSpot(TM) 64-Bit Server VM
file.encoding.pkg-------sun.io
sun.java.launcher-------SUN_STANDARD
user.country-------CN
sun.os.patch.level-------Service Pack 1
java.vm.specification.name-------Java Virtual Machine Specification
user.dir-------C:UsersAdministratorWorkspacesMyEclipse 10如何获取系统属性的键值对
java.runtime.version-------1.6.0_13-b03
java.awt.graphicsenv-------sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs-------D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jrelibendorsed
os.arch-------amd64
java.io.tmpdir-------C:UsersADMINI~1AppDataLocalTemp
line.separator-------
java.vm.specification.vendor-------Sun Microsystems Inc.
user.variant-------
os.name-------Windows Vista
sun.jnu.encoding-------GBK
java.library.path-------D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013bin;.;C:WindowsSunJavabin;C:Windowssystem32;C:Windows;C:Program Files (x86)Common FilesOracleJavajavapath;D:javabin;D:mysqlmysql-commercial-8.0.13-winx64bin;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Files (x86)Windows Kits8.1Windows Performance Toolkit;C:Program FilesMicrosoft SQL Server110ToolsBinn;C:Program FilesMicrosoftWeb Platform Installer;C:UsersAdministratorAppDataRoamingnpm;C:Program Files (x86)nodejs
java.specification.name-------Java Platform API Specification
java.class.version-------50.0
sun.management.compiler-------HotSpot 64-Bit Server Compiler
os.version-------6.1
user.home-------C:UsersAdministrator
user.timezone-------
java.awt.printerjob-------sun.awt.windows.WPrinterJob
file.encoding-------GBK
java.specification.version-------1.6
java.class.path-------C:UsersAdministratorWorkspacesMyEclipse 10如何获取系统属性的键值对bin
user.name-------Administrator
java.vm.specification.version-------1.0
java.home-------D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jre
sun.arch.data.model-------64
user.language-------zh
java.specification.vendor-------Sun Microsystems Inc.
awt.toolkit-------sun.awt.windows.WToolkit
java.vm.info-------mixed mode
java.version-------1.6.0_13
java.ext.dirs-------D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jrelibext;C:WindowsSunJavalibext
sun.boot.class.path-------D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jrelibresources.jar;D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jrelibrt.jar;D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jrelibsunrsasign.jar;D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jrelibjsse.jar;D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jrelibjce.jar;D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jrelibcharsets.jar;D:javaWebmyeclipseCommonbinarycom.sun.java.jdk.win32.x86_64_1.6.0.013jreclasses
java.vendor-------Sun Microsystems Inc.
file.separator-------
java.vendor.url.bug-------http://java.sun.com/cgi-bin/bugreport.cgi
sun.io.unicode.encoding-------UnicodeLittle
sun.cpu.endian-------little
sun.desktop-------windows
sun.cpu.isalist-------amd64
References
Imported packages in Java documentation: