java.lang.System.clearProperty()方法實例
java.lang.System.clearProperty() 方法刪除指定鍵指示的系統屬性。
聲明
以下是**java.lang.System.clearProperty()**方法的聲明
public static String clearProperty(String key)
參數
- key -- 此是要移除的系統屬性的名稱。
返回值
此方法返回系統屬性之前的字符串值,如果沒有此鍵的屬性,則返回null。
異常
SecurityException --如果安全管理器存在並且其checkPropertyAccess方法不允許訪問指定的系統屬性。
NullPointerException -- 如果key是null。
IllegalArgumentException -- 如果key是空的。
例子
下面的例子顯示java.lang.System.clearProperty()方法的使用。
package com.yiibai; import java.lang.*; public class SystemDemo { public static void main(String[] args) { // returns the previous string value of the system property String s = System.clearProperty("java.class.path"); // sets the system property System.setProperty("user.dir", "C:/yiibai/java"); // gets the system property after changes done by setProperty System.out.println(System.getProperty("user.dir")); } }
讓我們來編譯和運行上面的程序,這將產生以下結果:
C:/yiibai/java