static void setProperties(Properties props)
描述 (Description)
java.lang.System.setProperties()方法将系统属性设置为Properties参数。
声明 (Declaration)
以下是java.lang.System.setProperties()方法的声明public static void setProperties(Properties props)
参数 (Parameters)
props - 这是新的系统属性。
返回值 (Return Value)
此方法不返回任何值。
异常 (Exception)
SecurityException - 如果存在安全管理器且其checkPropertiesAccess方法不允许访问系统属性。
例子 (Example)
以下示例显示了java.lang.System.setProperties()方法的用法。package com.iowiki;
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