Get/set system property

ReturnMethodSummary
static StringclearProperty(String key)Removes the system property.
static Stringgetenv(String name)Gets the value of the specified environment variable.
static PropertiesgetProperties()Determines the current system properties.
static StringgetProperty(String key)Gets the system property.
static StringgetProperty(String key, String def)Gets the system property.
static voidsetProperties(Properties props)Sets the system properties to the Properties argument.
static StringsetProperty(String key, String value)Sets the system property.

The following properties are available:


public class Main {

  public static void main(String args[]) {
    System.setProperty("myKey", "myValue");
    
    System.out.println(System.getProperty("myKey"));

  }
}

The output:


myValue

Determine operating system using System class

 

public class Main {
  public static void main(String[] args) {
    String strOSName = System.getProperty("os.name");
    if (strOSName != null) {
      if (strOSName.toLowerCase().indexOf("windows") != -1)
        System.out.println("Windows");
      else
        System.out.print("not windows");
    }
  }
}

Windows
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.