java.lang.System.getProperty(String key)方法實例
java.lang.System.getProperty(String key) 方法獲取指定鍵指示的系統屬性。
聲明
以下是**java.lang.System.getProperty()**方法的聲明
public static String getProperty(String key)
參數
- key -- 此是該系統屬性的名稱。
返回值
此方法返回系統屬性的字符串值,如果沒有與此鍵的屬性則返回null。
異常
SecurityException -- 如果安全管理器存在並且其checkPropertyAccess方法不允許訪問指定的系統屬性。
NullPointerException -- 如果key是null。
IllegalArgumentException -- 如果key是空的。
例子
下面的例子顯示java.lang.System.getProperty()方法的使用。
package com.yiibai; import java.lang.*; public class SystemDemo { public static void main(String[] args) { // prints the name of the system property System.out.println(System.getProperty("user.dir")); // prints the name of the Operating System System.out.println(System.getProperty("os.name")); // prints Java Runtime Version System.out.println(System.getProperty("java.runtime.version" )); } }
讓我們來編譯和運行上面的程序,這將產生以下結果:
C:Program FilesJavajdk1.6.0_06in Windows XP 1.6.0_06-b02