如何在java中添加新的系统属性
是否可以向Java系统属性添加新值。 如果有任何方法可以在Java系统属性中引入具有相应值的新密钥。
System.setProperty
或启动JVM时使用-Dname=value
标志
是:
public static void main(String args[]) { String key = "a new property"; System.setProperty(key, "a property with a value"); System.out.println(System.getProperty(key)); }
System.setProperties(properties object);
这将设置系统属性。
如果要设置指定的属性,请使用
System.setProperty(key, value);//Both key and value should be string.
注意:这将首先检查权限,然后进行设置。 如果权限被拒绝,则可能发生SecurityException。