`

java获取系统属性和属性值

阅读更多
通过java可以获取系统信息,例如
System.getProperty("os.name");//获取操作系统名称

但是不知道除了os.name以外还有其它什么属性可以获取。
for (Enumeration e = System.getProperties().keys(); e.hasMoreElements();)
		       System.out.println(e.nextElement());

将打印出属性集
java.runtime.name
sun.boot.library.path
java.vm.version
java.vm.vendor
java.vendor.url
path.separator
java.vm.name
file.encoding.pkg
sun.java.launcher
user.country
sun.os.patch.level
java.vm.specification.name
user.dir
java.runtime.version
java.awt.graphicsenv
java.endorsed.dirs
os.arch
java.io.tmpdir
line.separator
java.vm.specification.vendor
user.variant
os.name
sun.jnu.encoding
java.library.path
java.specification.name
java.class.version
sun.management.compiler
os.version
user.home
user.timezone
java.awt.printerjob
file.encoding
java.specification.version
java.class.path
user.name
java.vm.specification.version
java.home
sun.arch.data.model
user.language
java.specification.vendor
awt.toolkit
java.vm.info
java.version
java.ext.dirs
sun.boot.class.path
java.vendor
file.separator
java.vendor.url.bug
sun.io.unicode.encoding
sun.cpu.endian
sun.desktop
sun.cpu.isalist


因为Properties继承了HashTable,所有我们可以通过以下方法获得操作系统信息的键值对
Set<Entry<Object, Object>> kk = System.getProperties().entrySet();
		for (Map.Entry<Object, Object> m1 : kk) {
			System.out.println(m1.getKey() + "==" + m1.getValue());
		}

打印出来的效果为:
java.runtime.name==Java(TM) SE Runtime Environment
sun.boot.library.path==D:\Java\jdk1.6.0_10\fastdebug\jre\bin
java.vm.version==1.6.0_10-ea-fastdebug-b08-fastdebug
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 3
java.vm.specification.name==Java Virtual Machine Specification
user.dir==D:\workspace\Test
java.runtime.version==1.6.0_10-ea-fastdebug-b08
java.awt.graphicsenv==sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs==D:\Java\jdk1.6.0_10\fastdebug\jre\lib\endorsed
os.arch==x86
java.io.tmpdir==C:\DOCUME~1\baomi\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==D:\Java\jdk1.6.0_10
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\baomi
user.timezone==
java.awt.printerjob==sun.awt.windows.WPrinterJob
file.encoding==UTF-8
java.specification.version==1.6
java.class.path==D:\workspace\Test\bin
user.name==baomi
java.vm.specification.version==1.0
java.home==D:\Java\jdk1.6.0_10\fastdebug\jre
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
java.version==1.6.0_10-ea-fastdebug
java.ext.dirs==D:\Java\jdk1.6.0_10\fastdebug\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
sun.boot.class.path==D:\Java\jdk1.6.0_10\fastdebug\jre\lib\resources.jar;D:\Java\jdk1.6.0_10\fastdebug\jre\lib\rt.jar;D:\Java\jdk1.6.0_10\fastdebug\jre\lib\sunrsasign.jar;D:\Java\jdk1.6.0_10\fastdebug\jre\lib\jsse.jar;D:\Java\jdk1.6.0_10\fastdebug\jre\lib\jce.jar;D:\Java\jdk1.6.0_10\fastdebug\jre\lib\charsets.jar;D:\Java\jdk1.6.0_10\fastdebug\jre\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==baomi
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics