In this section, you will learn how to modify the set of system properties by adding a new property. In the example given below, we have create a new property listed in the 'NewProperties.txt' file i.e java.company=Roseindia Pvt Ltd which is not an actual System Property.
Properties prop = new Properties(System.getProperties())- This statement initializes the new properties object, prop with the current set of system properties.
prop.load(propFile) - This method loads the additional property into prop from the file NewProperties.txt.
System.setProperties(prop)- This method takes the Properties object and add the property into the current system properties. It will change the set of system properties for the current running application.
Here is the code of GetSetProperties.java
On the console, you can see a newly added property:
Posted on: November 1, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles