Setting and Getting System Properties


System.setProperty("timezone", "EasternStandardTime"); String zone = System.getProperty("timezone");



System properties are key/value pairs that are external to your Java application. The Java System object provides a mechanism for reading the names and values of these external system properties into your Java application. The preceding phrase shows how you can set and get a system property using the Java System object.

You can also retrieve all the system properties into a properties object using the following statement:

Properties systemProps = System.getProperties();


There is also a method for retrieving just the system property names. The following code snippet shows how you can retrieve all the system property names and then retrieve each property using its name:

Properties props = System.getProperties(); Enumeration propertyNames = props.propertyNames(); String key = ""; while (propertyNames.hasMoreElements()) {      key = (String) propertyNames.nextElement();      System.out.println(key + "=" +          props.getProperty(key)); }





JavaT Phrasebook. Essential Code and Commands
Java Phrasebook
ISBN: 0672329077
EAN: 2147483647
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net