package javabse;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
/**
* 取得系统属性列表
* @author wxg1022
*
*/
public class TestSystemProperty {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//取得系统的属性列表
Properties properties=System.getProperties();
Enumeration<Object> e=properties.keys();
//或
/*while(e.hasMoreElements()){
String key=(String)e.nextElement();
String value=properties.getProperty(key);
System.out.println(key+"="+value);
}*/
Iterator<Object> i=properties.keySet().iterator();
while(i.hasNext()){
String key=(String)i.next();
String value=properties.getProperty(key);
System.out.println(key+"="+value);
}
}
}
运行结果如下:
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C:\Program Files\Java\jre6\bin
java.vm.version=11.0-b16
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
sun.java.launcher=SUN_STANDARD
user.country=CN
sun.os.patch.level=Service Pack 2
java.vm.specification.name=Java Virtual Machine Specification
user.dir=D:\dionysus\common\DemoTest
java.runtime.version=1.6.0_11-b03
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\jre6\lib\endorsed
os.arch=x86
java.io.tmpdir=C:\DOCUME~1\wxg1022\LOCALS~1\Temp\
line.separator=
java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows XP
sun.jnu.encoding=GBK
java.library.path=C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jre6\bin\client;C:\Program Files\Java\jre6\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Sybase\SQL Anywhere 8\win32;C:\Program Files\Sybase\Shared\win32;C:\Program Files\Sybase\Shared\Sybase Central 4.1;C:\Program Files\Sybase\PowerDynamo\win32;C:\Program Files\Sybase\Shared\PowerBuilder;C:\Program Files\Sybase\InfoMaker 9.0\Tutorial;C:\Program Files\Sybase\Shared\Web Targets;;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Java\jdk1.6.0_11\bin
java.specification.name=Java Platform API Specification
java.class.version=50.0
sun.management.compiler=HotSpot Client Compiler
os.version=5.1
user.home=C:\Documents and Settings\wxg1022
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=GBK
java.specification.version=1.6
java.class.path=D:\dionysus\common\DemoTest\build\classes;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\activation.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\annotations-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\ant.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\catalina-ant.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\catalina-ha.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\catalina-tribes.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\catalina.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\classes111.zip;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\classes12.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\classes12.zip;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-1.1.1-javadoc.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-1.1.1-sources.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-1.1.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-adapters-1.1.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-api-1.1.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-tests.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-modeler-2.0.1-javadoc.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-modeler-2.0.1-sources.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-modeler-2.0.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\el-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\j2ee.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jacob.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jasper-el.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jasper-jdt.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jasper.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\javaee.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jsp-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\mail.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\msbase.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\mssqlserver.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\msutil.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tomcat-coyote.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tomcat-dbcp.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tomcat-i18n-es.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tomcat-i18n-fr.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tomcat-i18n-ja.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tools.jar
user.name=wxg1022
java.vm.specification.version=1.0
java.home=C:\Program Files\Java\jre6
sun.arch.data.model=32
user.language=zh
java.specification.vendor=Sun Microsystems Inc.
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode, sharing
java.version=1.6.0_11
java.ext.dirs=C:\Program Files\Java\jre6\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
sun.boot.class.path=C:\Program Files\Java\jre6\lib\resources.jar;C:\Program Files\Java\jre6\lib\rt.jar;C:\Program Files\Java\jre6\lib\sunrsasign.jar;C:\Program Files\Java\jre6\lib\jsse.jar;C:\Program Files\Java\jre6\lib\jce.jar;C:\Program Files\Java\jre6\lib\charsets.jar;C:\Program Files\Java\jre6\classes
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=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
//还可以设置系统属性值
System.setProperty("java.version2","aa");
//设置多个
System.setProperties(Properties properties);
//移除
System.clearProperty("java.version2");
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
/**
* 取得系统属性列表
* @author wxg1022
*
*/
public class TestSystemProperty {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//取得系统的属性列表
Properties properties=System.getProperties();
Enumeration<Object> e=properties.keys();
//或
/*while(e.hasMoreElements()){
String key=(String)e.nextElement();
String value=properties.getProperty(key);
System.out.println(key+"="+value);
}*/
Iterator<Object> i=properties.keySet().iterator();
while(i.hasNext()){
String key=(String)i.next();
String value=properties.getProperty(key);
System.out.println(key+"="+value);
}
}
}
运行结果如下:
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C:\Program Files\Java\jre6\bin
java.vm.version=11.0-b16
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
sun.java.launcher=SUN_STANDARD
user.country=CN
sun.os.patch.level=Service Pack 2
java.vm.specification.name=Java Virtual Machine Specification
user.dir=D:\dionysus\common\DemoTest
java.runtime.version=1.6.0_11-b03
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\jre6\lib\endorsed
os.arch=x86
java.io.tmpdir=C:\DOCUME~1\wxg1022\LOCALS~1\Temp\
line.separator=
java.vm.specification.vendor=Sun Microsystems Inc.
user.variant=
os.name=Windows XP
sun.jnu.encoding=GBK
java.library.path=C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jre6\bin\client;C:\Program Files\Java\jre6\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Sybase\SQL Anywhere 8\win32;C:\Program Files\Sybase\Shared\win32;C:\Program Files\Sybase\Shared\Sybase Central 4.1;C:\Program Files\Sybase\PowerDynamo\win32;C:\Program Files\Sybase\Shared\PowerBuilder;C:\Program Files\Sybase\InfoMaker 9.0\Tutorial;C:\Program Files\Sybase\Shared\Web Targets;;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Java\jdk1.6.0_11\bin
java.specification.name=Java Platform API Specification
java.class.version=50.0
sun.management.compiler=HotSpot Client Compiler
os.version=5.1
user.home=C:\Documents and Settings\wxg1022
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=GBK
java.specification.version=1.6
java.class.path=D:\dionysus\common\DemoTest\build\classes;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\activation.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\annotations-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\ant.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\catalina-ant.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\catalina-ha.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\catalina-tribes.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\catalina.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\classes111.zip;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\classes12.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\classes12.zip;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-1.1.1-javadoc.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-1.1.1-sources.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-1.1.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-adapters-1.1.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-api-1.1.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-logging-tests.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-modeler-2.0.1-javadoc.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-modeler-2.0.1-sources.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\commons-modeler-2.0.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\el-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\j2ee.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jacob.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jasper-el.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jasper-jdt.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jasper.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\javaee.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jsp-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\mail.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\msbase.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\mssqlserver.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\msutil.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tomcat-coyote.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tomcat-dbcp.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tomcat-i18n-es.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tomcat-i18n-fr.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tomcat-i18n-ja.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\tools.jar
user.name=wxg1022
java.vm.specification.version=1.0
java.home=C:\Program Files\Java\jre6
sun.arch.data.model=32
user.language=zh
java.specification.vendor=Sun Microsystems Inc.
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode, sharing
java.version=1.6.0_11
java.ext.dirs=C:\Program Files\Java\jre6\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
sun.boot.class.path=C:\Program Files\Java\jre6\lib\resources.jar;C:\Program Files\Java\jre6\lib\rt.jar;C:\Program Files\Java\jre6\lib\sunrsasign.jar;C:\Program Files\Java\jre6\lib\jsse.jar;C:\Program Files\Java\jre6\lib\jce.jar;C:\Program Files\Java\jre6\lib\charsets.jar;C:\Program Files\Java\jre6\classes
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=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
//还可以设置系统属性值
System.setProperty("java.version2","aa");
//设置多个
System.setProperties(Properties properties);
//移除
System.clearProperty("java.version2");