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


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


描述

這個java.lang.System.clearProperty() 方法刪除指定鍵指示的係統屬性。

聲明

以下是聲明java.lang.System.clearProperty()方法

public static String clearProperty(String key)

參數

key- 這是要刪除的係統屬性的名稱。

返回值

此方法返回係統屬性的前一個字符串值,如果沒有該鍵的屬性,則返回 null。

異常

  • SecurityException- 如果安全管理器存在並且其 checkPropertyAccess 方法不允許訪問指定的係統屬性。

  • NullPointerException- 如果鍵為空。

  • IllegalArgumentException- 如果鍵為空。

示例

下麵的例子展示了 java.lang.System.clearProperty() 方法的用法。

package com.tutorialspoint;

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:/tutorialspoint/java");

      // gets the system property after changes done by setProperty
      System.out.println(System.getProperty("user.dir"));
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果 -

C:/tutorialspoint/java

相關用法


注:本文由純淨天空篩選整理自 Java.lang.System.clearProperty() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。