java.lang.System.getProperties()方法實例
java.lang.System.getProperties() 方法確定當前係統屬性。當前設置用於通過getProperty(String)方法使用係統屬性返回一個Properties對象。
如果冇有當前係統屬性的集合,那麼它首先創建並初始化係統屬性的集合。這套係統屬性包括以下鍵的值:
Key | 關聯值的說明 |
---|---|
java.version | Java Runtime Environment version |
java.vendor | Java Runtime Environment vendor |
java.vendor.url | Java vendor URL |
java.home | Java installation directory |
java.vm.specification.version | Java Virtual Machine specification version |
java.vm.specification.vendor | Java Virtual Machine specification vendor |
java.vm.specification.name | Java Virtual Machine specification name |
java.vm.version | Java Virtual Machine implementation version |
java.vm.vendor | Java Virtual Machine implementation vendor |
java.vm.name | Java Virtual Machine implementation name |
java.specification.version | Java Runtime Environment specification version |
java.specification.vendor | Java Runtime Environment specification vendor |
java.specification.name | Java Runtime Environment specification name |
java.class.version | Java class format version number |
java.class.path | Java class path |
java.library.path | List of paths to search when loading libraries |
java.io.tmpdir | Default temp file path |
java.compiler | Name of JIT compiler to use |
java.ext.dirs | Path of extension directory or directories |
os.name | Operating system name |
os.arch | Operating system architecture |
os.version | Operating system version |
file.separator | File separator ("/" on UNIX) |
path.separator | Path separator (":" on UNIX) |
line.separator | Line separator (" " on UNIX) |
user.name | User's account name |
user.home | User's home directory |
user.dir | User's current working directory |
聲明
以下是java.lang.System.getProperties()方法的聲明
public static Properties getProperties()
參數
-
NA
返回值
此方法返回係統屬性。
異常
-
SecurityException -- 如果安全管理器存在並且其checkPermission方法不允許訪問過程中的環境。
例子
下麵的例子顯示java.lang.System.getProperties()方法的使用。
package com.yiibai; import java.lang.*; public class SystemDemo { public static void main(String[] args) { // this will list the current system properties Properties p = System.getProperties(); p.list(System.out); } }
讓我們來編譯和運行上麵的程序,這將產生以下結果:
-- listing properties -- java.runtime.name=Java(TM) SE Runtime Environment sun.boot.library.path=C:Program FilesJavajdk1.6.0_06jre... java.vm.version=10.0-b22 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=US sun.java.launcher=SUN_STANDARD sun.os.patch.level=Service Pack 2 java.vm.specification.name=Java Virtual Machine Specification user.dir=C:Program FilesJavajdk1.6.0_06in java.runtime.version=1.6.0_06-b02 java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment java.endorsed.dirs=C:Program FilesJavajdk1.6.0_06jre... os.arch=x86 java.io.tmpdir=C:DOCUME~1AMIT~1.AMILOCALS~1Temp line.separator= java.vm.specification.vendor=Sun Microsystems Inc. user.variant= os.name=Windows XP sun.jnu.encoding=Cp1252 java.library.path=C:Program FilesJavajdk1.6.0_06in... 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 Settingsamit.AMIT-4... user.timezone= java.awt.printerjob=sun.awt.windows.WPrinterJob file.encoding=Cp1252 java.specification.version=1.6 user.name=amit java.class.path=. java.vm.specification.version=1.0 sun.arch.data.model=32 java.home=C:Program FilesJavajdk1.6.0_06jre java.specification.vendor=Sun Microsystems Inc. user.language=en awt.toolkit=sun.awt.windows.WToolkit java.vm.info=mixed mode, sharing java.version=1.6.0_06 java.ext.dirs=C:Program FilesJavajdk1.6.0_06jre... sun.boot.class.path=C:Program FilesJavajdk1.6.0_06jre... java.vendor=Sun Microsystems Inc. file.separator= java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport... sun.cpu.endian=little sun.io.unicode.encoding=UnicodeLittle sun.desktop=windows sun.cpu.isalist=