Jump to Real's How-to Main page

Retrieve environment variables (JDK1.5)

JDK1.5
System.getenv() is back!
import java.util.*;

public class Test {
 public static void main(String args[]) {
   // just one
   System.out.println("PATH = " + System.getenv("PATH"));

   // all of them
   Map env = System.getenv();
   for (Iterator it=env.entrySet().iterator(); it.hasNext(); ) {
      Map.Entry entry = (Map.Entry)it.next();
      System.out.println(entry.getKey() + " = " + entry.getValue());
    }
 }
}

See also this HowTo.

See this Howto for common XP environment variables


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]