今天有人问我Java Runtime 的一些属性,就索性敲了几行代码。
import java.util.*;
public class GetSysProperty {
public static void main(String[] args) {
int s = System.getProperties().size();
System.out.println("System Properties Number: " + s + "\r\n");
Enumeration e = System.getProperties().keys();
Collection v = System.getProperties().values();
for (Iterator iter = v.iterator(); iter.hasNext(); e.hasMoreElements()) {
System.out.println(prtSpace(e.nextElement().toString()) + " = "
+ iter.next());
}
}
public static String prtSpace(String s) {
int LENGTH = 40;
int nLen = s.length();
int sLen = LENGTH - nLen;
if (sLen > 0) {
for (int i = 0; i < sLen; i++) {
s += " ";
}
}
return s;
}
}
一个运行实例:
System Properties Number: 50
java.runtime.name = Java(TM) 2 Runtime Environment, Standard Edition
sun.boot.library.path = C:\Program Files\Java\j2re1.4.2\bin
java.vm.version = 1.4.2-b28
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
user.country = CN
sun.os.patch.level = Service Pack 4
java.vm.specification.name = Java Virtual Machine Specification
user.dir = D:\eww\test
java.runtime.version = 1.4.2-b28
java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs = C:\Program Files\Java\j2re1.4.2\lib\endorsed
os.arch = x86
java.io.tmpdir = C:\DOCUME~1\ADMINI~1\LOCALS~1\Templine.separator =
java.vm.specification.vendor = Sun Microsystems Inc.
user.variant =
os.name = Windows 2000
sun.java2d.fontpath =
java.library.path = C:\Program Files\Java\j2re1.4.2\bin;.;C:\WINNT\system32;C:\WINNT;c:\oracle\ora90\bin;C:\Program Files\Oracle\jre\1.1.8\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;D:\j2sdk1.4.2\bin;D:\UnxUtils\usr\local\wbin;C:\PROGRA~1\TCL\bin
java.specification.name = Java Platform API Specification
java.class.version = 48.0
java.util.prefs.PreferencesFactory = java.util.prefs.WindowsPreferencesFactory
os.version = 5.0
user.home = C:\Documents and Settings\Administrator
user.timezone =
java.awt.printerjob = sun.awt.windows.WPrinterJob
file.encoding = GBK
java.specification.version = 1.4
java.class.path = D:\eww\test\bin;D:\lib\ABS.jar;D:\lib\activation.jar;D:\lib\axis.jar;D:\lib\axis-ant.jar;D:\lib\commons-beanutils.jar;D:\lib\commons-codec-1.1.jar;D:\lib\commons-collections.jar;D:\lib\commons-dbcp.jar;D:\lib\commons-digester.jar;D:\lib\commons-discovery.jar;D:\lib\commons-fileupload.jar;D:\lib\commons-lang.jar;D:\lib\commons-lang-2.0.jar;D:\lib\commons-logging.jar;D:\lib\commons-pool.jar;D:\lib\commons-resources.jar;D:\lib\commons-validator.jar;D:\lib\cos.jar;D:\lib\dfbeans.jar;D:\lib\dfmerp.jar;D:\lib\jakarta-oro.jar;D:\lib\jakarta-oro-2.0.6.jar;D:\lib\jakarta-poi-1.9.0-dev-20030109.jar;D:\lib\jaxrpc.jar;D:\lib\jcms_sysinfo.jar;D:\lib\jconn2.jar;D:\lib\jdom.jar;D:\lib\ldapMd5.jar;D:\lib\LDAPpart.jar;D:\lib\log4j-1.2.8.jar;D:\lib\lucene_cn.jar;D:\lib\lucene-demos-20030724.jar;D:\lib\mail.jar;D:\lib\msbase.jar;D:\lib\mssqlserver.jar;D:\lib\msutil.jar;D:\lib\news_filter.jar;D:\lib\nls_charset12.jar;D:\lib\nntp.jar;D:\lib\OaBasicClass.jar;D:\lib\oracle12.jar;D:\lib\platform.jar;D:\lib\saaj.jar;D:\lib\servlet.jar;D:\lib\sprinta2000_enterprise.jar;D:\lib\velocity-dep-1.4.jar;D:\lib\workflow.jar;D:\lib\workflowserver.jar;D:\lib\wsdl4j.jar;D:\lib\allmodal.jar;D:\lib\jcms_luc.jar;D:\lib\junit.jar;D:\lib\jrlib.jar;D:\lib\mysql-connector-java-3.1.4-beta-bin.jar
user.name = Administrator
java.vm.specification.version = 1.0
java.home = C:\Program Files\Java\j2re1.4.2
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.4.2
java.ext.dirs = C:\Program Files\Java\j2re1.4.2\lib\ext
sun.boot.class.path = C:\Program Files\Java\j2re1.4.2\lib\rt.jar;C:\Program Files\Java\j2re1.4.2\lib\i18n.jar;C:\Program Files\Java\j2re1.4.2\lib\sunrsasign.jar;C:\Program Files\Java\j2re1.4.2\lib\jsse.jar;C:\Program Files\Java\j2re1.4.2\lib\jce.jar;C:\Program Files\Java\j2re1.4.2\lib\charsets.jar;C:\Program Files\Java\j2re1.4.2\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.cpu.isalist = pentium i486 i386