CODE:
//Java遍历系统变量
import java.util.*;
/**
* 在jdk1.4中想获取缺省的编码格式,没有好的办法,但是可以从系统变量中读取。
* 54powerman
* http://54powerman.blog.sohu.com
**/
public class EnumerateProperties
{
public static void main(String [] args) throws Exception{
Properties prop=System.getProperties();
Enumeration enum=prop.propertyNames();
String key=null;
while(enum.hasMoreElements())
{
key=enum.nextElement().toString();
System.out.println(key+" = "+prop.getProperty(key));
}
}
}
OUT:
---------- Run Java ----------
java.runtime.name = Java(TM) 2 Runtime Environment, Standard Edition
sun.boot.library.path = C:/Program Files/Java/j2re1.4.2_13/bin
java.vm.version = 1.4.2_13-b06
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 = C:/Documents and Settings/Administrator/桌面
java.runtime.version = 1.4.2_13-b06
java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs = C:/Program Files/Java/j2re1.4.2_13/lib/endorsed
os.arch = x86
java.io.tmpdir = C:/DOCUME~1/BAOLID~1/LOCALS~1/Temp/
line.separator =
java.vm.specification.vendor = Sun Microsystems Inc.
user.variant =
os.name = Windows 2000
sun.java2d.fontpath =
java.library.path = C:/WINNT/system32;.;C:/WINNT/system32;C:/WINNT;C:/j2sdk1.4.2_13/bin;c:/program files/imagemagick-6.2.9-q16;D:/oracle/product/10.2.0/db_1/bin;C:/WINNT/system32;C:/WINNT;C:/WINNT/System32/Wbem;C:/PROGRA~1/SECUREFX;C:/Program Files/SecureCRT/;C:/WINNT/Downloaded Program Files/;C:/Program Files/IDM Computer Solutions/UltraEdit-32;C:/Program Files/Private Shell;C:/Program Files/EditPlus 2;C:/j2sdk1.4.2_13/bin;C:/j2sdk1.4.2_13/bin;c:/program files/imagemagick-6.2.9-q16;D:/oracle/product/10.2.0/db_1/bin;C:/WINNT/system32;C:/WINNT;C:/WINNT/System32/Wbem;C:/PROGRA~1/SECUREFX;C:/Program Files/SecureCRT/;C:/WINNT/Downloaded Program Files/;C:/Program Files/IDM Computer Solutions/UltraEdit-32;C:/Program Files/Private Shell;;E:/Program Files/apache-ant-1.6.5/bin;C:/Program Files/IDM Computer Solutions/UltraCompare;e:/program files/bat;
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
user.name = Administrator
java.class.path = .;./classes;C:/j2sdk1.4.2_13/lib/dt.jar;C:/j2sdk1.4.2_13/lib/tools.jar;D:/Projects/lib/comm/comm.jar;C:/axis-1_4/lib/axis.jar;C:/axis-1_4/lib/commons-discovery-0.2.jar;C:/axis-1_4/lib/commons-logging-1.0.4.jar;C:/axis-1_4/lib/jaxrpc.jar;C:/axis-1_4/lib/saaj.jar;C:/axis-1_4/lib/log4j-1.2.8.jar;C:/axis-1_4/lib/wsdl4j-1.5.1.jar;C:/axis-1_4/lib/axis-ant.jar;C:/axis-1_4/lib/activation.jar;C:/axis-1_4/lib/mail.jar;;D:/Projects/lib/db/classes12.jar;D:/Projects/lib/db/mssqlserver.jar;D:/Projects/lib/db/snappool.v1.14.jar;D:/Projects/lib/db/mmmysql-204-bin.jar;D:/Projects/mmsfile/MMSLibrary.jar;D:/Projects/lib/httpclient/commons-httpclient-3.0.1.jar;D:/Projects/lib/httpclient/commons-codec-1.3.jar;D:/Projects/lib/httpclient/commons-logging-1.1.jar;D:/Projects/lib/httpclient/commons-logging-adapters-1.1.jar;D:/Projects/lib/httpclient/commons-logging-api-1.1.jar;
java.vm.specification.version = 1.0
sun.arch.data.model = 32
java.home = C:/Program Files/Java/j2re1.4.2_13
java.specification.vendor = Sun Microsystems Inc.
user.language = zh
awt.toolkit = sun.awt.windows.WToolkit
java.vm.info = mixed mode
java.version = 1.4.2_13
java.ext.dirs = C:/Program Files/Java/j2re1.4.2_13/lib/ext
sun.boot.class.path = C:/Program Files/Java/j2re1.4.2_13/lib/rt.jar;C:/Program Files/Java/j2re1.4.2_13/lib/i18n.jar;C:/Program Files/Java/j2re1.4.2_13/lib/sunrsasign.jar;C:/Program Files/Java/j2re1.4.2_13/lib/jsse.jar;C:/Program Files/Java/j2re1.4.2_13/lib/jce.jar;C:/Program Files/Java/j2re1.4.2_13/lib/charsets.jar;C:/Program Files/Java/j2re1.4.2_13/classes
java.vendor = Sun Microsystems Inc.
file.separator = /
java.vendor.url.bug = http://java.sun.com/cgi-bin/bugreport.cgi
sun.cpu.endian = little
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.isalist = pentium i486 i386
输出完成 (耗时: 0 秒) - 正常终止