Environment variables are accessed using the System.getEnv() method, which comes in two flavours:
- Flavour 1: iterate around a map of all environment variables.
- Falvour 2: get a particular variable
    // Flavour 1: iterate around a map of all environment variables.
    Map<String, String> env = System.getenv();
    for (Map.Entry<String, String> entry : env.entrySet()) {
      System.out.println("Key: " + entry.getKey() + " value: " + entry.getValue());
    }    // Falvour 2: get a particular variable
    System.out.println("\n\nJ2EE_HOME is: " + System.getenv("J2EE_HOME"));
    System.out.println("\n\nPATH is: " + System.getenv("PATH")); 
 
No comments:
Post a comment