java system类
系统类clearProperty()方法 (System class clearProperty() method)
clearProperty() method is available in java.lang package.
clearProperty()方法在java.lang包中可用。
clearProperty() method is used to remove or clear the property value denoted by the given argument (property_name).
clearProperty()方法用于删除或清除由给定参数(property_name)表示的属性值。
clearProperty() method is static so this method is accessible with the class name too.
clearProperty()方法是静态的,因此也可以使用类名访问此方法。
clearProperty() method may be thrown various type of exception and the exception are given below:
clearProperty()方法可能会引发各种类型的异常,该异常如下所示:
- SecurityException: If a particular method checkPropertyAcess() does not allow access to the given system property in the method.SecurityException:如果特定方法checkPropertyAcess()不允许访问该方法中的给定系统属性。
- NullPointerException: If the given system property is null.NullPointerException:如果给定的系统属性为null。
- IllegalArgumentException: If the given system property value is empty.IllegalArgumentException:如果给定的系统属性值为空。
Syntax:
句法:
public static String clearProperty(String property);
Parameter(s):
参数:
property – represents the name of the property to be removed.
property –表示要删除的属性的名称。
Return value:
返回值:
The return type of this method is String, it returns the old string value of the System property and if there is no property value with that "property_name", it returns null.
此方法的返回类型为String ,它返回System属性的旧字符串值,如果没有带有该“ property_name”的属性值,则返回null。
Example:
例:
// 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"));
}
}
Output
输出量
E:\Programs>javac ClearPropertyMethod.java
E:\Programs>java ClearPropertyMethod
root
After clearProperty()...
null
翻译自: https://www.includehelp.com/java/system-class-clearproperty-method-with-example.aspx
java system类