How to add new System Properties in java

ε祈祈猫儿з 提交于 2019-11-30 01:05:30

问题


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.


回答1:


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




回答2:


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));
}



回答3:


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.



来源:https://stackoverflow.com/questions/9736862/how-to-add-new-system-properties-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!