Java程序查询系统参数

Java程序查询系统参数

系统参数就是系统中设定的一些参数,比如系统名称、JVM的版本等。Java的程序可以跨平台执行,可以通过这些系统参数的值目前执行的环境是怎样的,然后程序在执行的时候可以根据不同平台的特性,动态的做最佳的调整。下面代码可以取得系统参数。

package test;

import java.util.Enumeration;
import java.util.Properties;


public class Test {

	public static void main(String args[]){
		Properties p = System.getProperties();
		Enumeration enume = p.propertyNames();
		String propertyName = "";
		String property = "";
		while( enume.hasMoreElements()){
			propertyName = (String)enume.nextElement();
			property = p.getProperty(propertyName);
			System.out.println("Property "+ propertyName +"' = '"+property+"'");
		}
	}
}

运行的结果是:

Property java.runtime.name' = 'Java(TM) SE Runtime Environment'
Property sun.boot.library.path' = 'C:\Program Files\Java\jre7\bin'
Property java.vm.version' = '23.25-b01'
Property java.vm.vendor' = 'Oracle Corporation'
Property java.vendor.url' = 'http://java.oracle.com/'
Property path.separator' = ';'
Property java.vm.name' = 'Java HotSpot(TM) Client VM'
Property file.encoding.pkg' = 'sun.io'
Property user.script' = ''
Property user.country' = 'CN'
Property sun.java.launcher' = 'SUN_STANDARD'
Property sun.os.patch.level' = 'Service Pack 1'
Property java.vm.specification.name' = 'Java Virtual Machine Specification'
Property user.dir' = 'C:\Users\Administrator\workspace\Test'
Property java.runtime.version' = '1.7.0_25-b17'
Property java.awt.graphicsenv' = 'sun.awt.Win32GraphicsEnvironment'
Property java.endorsed.dirs' = 'C:\Program Files\Java\jre7\lib\endorsed'
Property os.arch' = 'x86'
Property java.io.tmpdir' = 'C:\Users\ADMINI~1\AppData\Local\Temp\'
Property line.separator' = '
'
Property java.vm.specification.vendor' = 'Oracle Corporation'
Property user.variant' = ''
Property os.name' = 'Windows 7'
Property sun.jnu.encoding' = 'GBK'
Property java.library.path' = 'C:\Program Files\Java\jre7\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;D:\app\Administrator\product\11.2.0\dbhome_1\bin;C:\Program Files\Java\jdk1.7.0_25;D:\Program Files\Java\jdk1.6.0_27;\bin;C:\Program Files\Java\jdk1.7.0_25;D:\Program Files\Java\jdk1.6.0_27;\jre\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;D:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;D:\Program Files\Java\jdk1.6.0_27;\bin;D:\Program Files\Java\jdk1.6.0_27;\jre\bin;d:\Program Files\Windows7Master;D:\Program Files\MySQL\MySQL Utilities 1.3.4\;D:\Program Files\MATLAB\R2010b\runtime\win32;D:\Program Files\MATLAB\R2010b\bin;C:\Program Files\jEdit;D:\eclipse;;.'
Property java.specification.name' = 'Java Platform API Specification'
Property java.class.version' = '51.0'
Property sun.management.compiler' = 'HotSpot Client Compiler'
Property os.version' = '6.1'
Property user.home' = 'C:\Users\Administrator'
Property user.timezone' = ''
Property java.awt.printerjob' = 'sun.awt.windows.WPrinterJob'
Property file.encoding' = 'GBK'
Property java.specification.version' = '1.7'
Property user.name' = 'Administrator'
Property java.class.path' = 'C:\Users\Administrator\workspace\Test\bin'
Property java.vm.specification.version' = '1.7'
Property sun.arch.data.model' = '32'
Property java.home' = 'C:\Program Files\Java\jre7'
Property sun.java.command' = 'test.Test'
Property java.specification.vendor' = 'Oracle Corporation'
Property user.language' = 'zh'
Property awt.toolkit' = 'sun.awt.windows.WToolkit'
Property java.vm.info' = 'mixed mode, sharing'
Property java.version' = '1.7.0_25'
Property java.ext.dirs' = 'C:\Program Files\Java\jre7\lib\ext;C:\windows\Sun\Java\lib\ext'
Property sun.boot.class.path' = 'C:\Program Files\Java\jre7\lib\resources.jar;C:\Program Files\Java\jre7\lib\rt.jar;C:\Program Files\Java\jre7\lib\sunrsasign.jar;C:\Program Files\Java\jre7\lib\jsse.jar;C:\Program Files\Java\jre7\lib\jce.jar;C:\Program Files\Java\jre7\lib\charsets.jar;C:\Program Files\Java\jre7\lib\jfr.jar;C:\Program Files\Java\jre7\classes'
Property java.vendor' = 'Oracle Corporation'
Property file.separator' = '\'
Property java.vendor.url.bug' = 'http://bugreport.sun.com/bugreport/'
Property sun.cpu.endian' = 'little'
Property sun.io.unicode.encoding' = 'UnicodeLittle'
Property sun.desktop' = 'windows'
Property sun.cpu.isalist' = 'pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86'
当然,不同的平台所得到的结果会不一样。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值