Java.lang.System.clearProperty() 方法
描述
java.lang.System.clearProperty() 方法删除指定键指示的系统属性。
声明
以下是 java.lang.System.clearProperty() 方法的声明。
public static String clearProperty(String key)
参数
key − 这是要删除的系统属性的名称。
返回值
此方法返回系统属性的前一个字符串值,如果没有具有该键的属性,则返回 null。
异常
SecurityException − 如果存在安全管理器并且其 checkPropertyAccess 方法不允许访问指定的系统属性。
NullPointerException − 如果键为 null。
IllegalArgumentException − 如果键为 empty。
示例
下面的例子展示了 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

