當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java System clearProperty()用法及代碼示例

System類clearProperty()方法

  • clearProperty() 方法可在java.lang包。
  • clearProperty() 方法用於刪除或清除給定參數 (property_name) 表示的屬性值。
  • clearProperty() 方法是靜態的,所以這個方法也可以用類名訪問。
  • clearProperty() 方法可能會拋出各種類型的異常,異常如下:
    • 安全異常:如果特定方法 checkPropertyAcess() 不允許訪問該方法中的給定係統屬性。
    • NullPointerException :如果給定的係統屬性為空。
    • 非法參數異常:如果給定的係統屬性值為空。

用法:

    public static String clearProperty(String property);

參數:

  • property– 表示要刪除的屬性的名稱。

返回值:

這個方法的返回類型是String,它返回 System 屬性的舊字符串值,如果該 "property_name" 沒有屬性值,則返回 null。

例:

// Java program to demonstrate the example of 
// clearProperty() method of System Class.

public class ClearPropertyMethod {
    public static void main(String[] args) {
        // By using  getProperty() method is used 
        // to get the value of the property
        System.out.println(System.getProperty("user.name"));

        // By using  clearProperty() method is used to 
        // clear the value of the property
        System.clearProperty("user.name");

        // Display the value of the property
        System.out.println("After clearProperty()...");
        System.out.println(System.getProperty("user.name"));
    }
}

輸出

E:\Programs>javac ClearPropertyMethod.java
E:\Programs>java ClearPropertyMethod
root
After clearProperty()...
null


相關用法


注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java System class clearProperty() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。