目录

static String clearProperty(String key)

描述 (Description)

java.lang.System.clearProperty()方法删除指定键指示的系统属性。

声明 (Declaration)

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

public static String clearProperty(String key)

参数 (Parameters)

key - 这是要删除的系统属性的名称。

返回值 (Return Value)

此方法返回系统属性的先前字符串值,如果没有具有该键的属性,则返回null。

异常 (Exception)

  • SecurityException - 如果存在安全管理器且其checkPropertyAccess方法不允许访问指定的系统属性。

  • NullPointerException - 如果key为null。

  • IllegalArgumentException - 如果key为空。

例子 (Example)

以下示例显示了java.lang.System.clearProperty()方法的用法。

package com.iowiki;
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:/iowiki/java");
      // gets the system property after changes done by setProperty
      System.out.println(System.getProperty("user.dir"));
   }
} 

让我们编译并运行上面的程序,这将产生以下结果 -

C:/iowiki/java
↑回到顶部↑
WIKI教程 @2018