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:
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: November 1, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles