Java.lang.System.setProperties() 方法
描述
java.lang.System.setProperties() 方法将系统属性设置为 Properties 参数。
声明
以下是 java.lang.System.setProperties() 方法的声明。
public static void setProperties(Properties props)
参数
props − 这是新的系统属性。
返回值
此方法不返回任何值。
异常
SecurityException − 如果存在安全管理器并且其 checkPropertiesAccess 方法不允许访问系统属性。
示例
下面的例子展示了 java.lang.System.setProperties() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class SystemDemo {
public static void main(String[] args) {
// prints Java Runtime Version before property set
System.out.print("Previous : ");
System.out.println(System.getProperty("java.runtime.version"));
Properties p = System.getProperties();
p.put("java.runtime.version", "Java Runtime 1.6.0");
System.setProperties(p);
// prints Java Runtime Version after property set
System.out.print("New : ");
System.out.println(System.getProperty("java.runtime.version"));
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Previous : 1.6.0_22-b22 New : Java Runtime 1.6.0

