Writing System Properties

28 May 2008

System’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.

del.icio.us:Writing System Properties  digg:Writing System Properties  spurl:Writing System Properties  wists:Writing System Properties  simpy:Writing System Properties  newsvine:Writing System Properties  blinklist:Writing System Properties  furl:Writing System Properties  reddit:Writing System Properties  fark:Writing System Properties  blogmarks:Writing System Properties  Y!:Writing System Properties  smarking:Writing System Properties  magnolia:Writing System Properties  segnalo:Writing System Properties  gifttagging:Writing System Properties

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

Leave a Reply