Writing System Properties
28 May 2008System’s setProperties() method can be used to modify eyisting system’s property. It takes a Properties object that has been initialized to contain the key/value pairs for the properties that you want to set.
This method actually replaces the entire set of system properties with the new set Properties object. Lets review an example that creates a Properties object,initializes it from a file and then uses System.setProperties() to install the new Properties objects as the current set of system properties.
import java.io.FileInputStream; import java.util.Properties; class PropertiesTest { public static void main(String args[]) { try { // set up new properties object from file "myProperties.txt" FileInputStream propFile = new FileInputStream("myProperties.txt"); Properties p = new Properties(System.getProperties()); p.load(propFile); // set the system properties System.setProperties(p); System.getProperties().list(System.out); } catch (java.io.FileNotFoundException e) { ; } catch (java.io.IOException e) { ; } } }
Hope you find this useful.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Writing System Properties