How to add new System Properties in java

2019-02-11 13:05发布

Is it possible to add new values to Java System Properties. If there is any how can introduce new keys with there corresponding values in Java System Properties.

3条回答
Deceive 欺骗
2楼-- · 2019-02-11 13:13

Either System.setProperty or use the -Dname=value flag when you start the JVM

查看更多
Ridiculous、
3楼-- · 2019-02-11 13:24

Yes:

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));
}
查看更多
Ridiculous、
4楼-- · 2019-02-11 13:25
System.setProperties(properties object);

This will set the system properties.

If you want to set a specified property, then use

System.setProperty(key, value);//Both key and value should be string.

NOTE: This will first check the permission and then set it. If permission denied, then SecurityException may occur.

查看更多
登录 后发表回答