学习java过程中,常常需要获取系统属性,每次都要去查,而且多不全面........今记此文,希望能带来些许方便,,懒人啊.........
// 以下代码获取系统当前设置的环境变量,,,各系统的值是不一样的
System.out.println("//");
System.out.println("System Enviroment :");Map<String,String> sysMap = System.getenv();
Iterator<String> itr = sysMap.keySet().iterator();
while(itr.hasNext()){
System.out.println(sysMap.get(itr.next()));
}
// 以下代买获取系统属性
System.out.println("//");
System.out.println("System Properties :");
Properties prop = System.getProperties();
Iterator pitr = prop.keySet().iterator();
while(pitr.hasNext()){
Object key = pitr.next();
System.out.println("key : " + key+ " ; value : " + prop.getProperty(key.toString()));
}
以下是系统属性的key 和value :
System Properties :
key : java.runtime.name ; value : Java(TM) SE Runtime Environment
key : sun.boot.library.path ; value : D:\Program Files\Java\jre7\bin
key : java.vm.version ; value : 21.0-b17
key : java.vm.vendor ; value : Oracle Corporation
key : java.vendor.url ; value : http://java.oracle.com/
key : path.separator ; value : ;
key : java.vm.name ; value : Java HotSpot(TM) Client VM
key : file.encoding.pkg ; value : sun.io
key : user.country ; value : CN
key : user.script ; value :
key : sun.java.launcher ; value : SUN_STANDARD
key : sun.os.patch.level ; value : Service Pack 1
key : java.vm.specification.name ; value : Java Virtual Machine Specification
key : user.dir ; value : E:\git\android\projects\ACM
key : java.runtime.version ; value : 1.7.0-b147
key : java.awt.graphicsenv ; value : sun.awt.Win32GraphicsEnvironment
key : java.endorsed.dirs ; value : D:\Program Files\Java\jre7\lib\endorsed
key : os.arch ; value : x86
key : java.io.tmpdir ; value : C:\Users\ADMINI~1\AppData\Local\Temp\
key : line.separator ; value :
key : java.vm.specification.vendor ; value : Oracle Corporation
key : user.variant ; value :
key : os.name ; value : Windows 7
key : sun.jnu.encoding ; value : GBK
key : java.library.path ; value : D:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/Program Files/Java/jre7/bin/client;D:/Program Files/Java/jre7/bin;D:/Program Files/Java/jre7/lib/i386;C:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Windows7Master;d:\Program Files\Git\cmd;D:\Program Files\Java\jdk1.7.0\bin;D:\Program Files\Java\jdk1.7.0\lib\dt.jar;D:\Program Files\Java\jdk1.7.0\lib\tools.jar;D:\android\android-sdk;D:\android\android-sdk\tools;D:\android\android-sdk\platform-tools;D:\Program Files\Sqlite\sqlite3.exe;D:\Program Files\Sqlite\SQLiteBrowser.exe;D:\tomcat-6\lib;;D:\eclipse;;.
key : java.specification.name ; value : Java Platform API Specification
key : java.class.version ; value : 51.0
key : sun.management.compiler ; value : HotSpot Client Compiler
key : os.version ; value : 6.1
key : user.home ; value : C:\Users\Administrator
key : user.timezone ; value :
key : java.awt.printerjob ; value : sun.awt.windows.WPrinterJob
key : file.encoding ; value : GBK
key : java.specification.version ; value : 1.7
key : java.class.path ; value : E:\git\android\projects\ACM\bin
key : user.name ; value : Administrator
key : java.vm.specification.version ; value : 1.7
key : sun.java.command ; value : com.xy.osname.GetOperatingSystemType
key : java.home ; value : D:\Program Files\Java\jre7
key : sun.arch.data.model ; value : 32
key : user.language ; value : zh
key : java.specification.vendor ; value : Oracle Corporation
key : awt.toolkit ; value : sun.awt.windows.WToolkit
key : java.vm.info ; value : mixed mode, sharing
key : java.version ; value : 1.7.0
key : java.ext.dirs ; value : D:\Program Files\Java\jre7\lib\ext;C:\Windows\Sun\Java\lib\ext
key : sun.boot.class.path ; value : D:\Program Files\Java\jre7\lib\resources.jar;D:\Program Files\Java\jre7\lib\rt.jar;D:\Program Files\Java\jre7\lib\sunrsasign.jar;D:\Program Files\Java\jre7\lib\jsse.jar;D:\Program Files\Java\jre7\lib\jce.jar;D:\Program Files\Java\jre7\lib\charsets.jar;D:\Program Files\Java\jre7\classes
key : java.vendor ; value : Oracle Corporation
key : file.separator ; value : \
key : java.vendor.url.bug ; value : http://bugreport.sun.com/bugreport/
key : sun.io.unicode.encoding ; value : UnicodeLittle
key : sun.cpu.endian ; value : little
key : sun.desktop ; value : windows
key : sun.cpu.isalist ; value : pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86