home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Java Fundamental Classes Reference

Previous Chapter 10
Accessing the Environment

10.3 Environment Variables

Java does not provide any way to directly access environment variables defined on a system. There is a System.getEnv() method that served that purpose before Java 1.0 was released. However, in released versions of Java, the System.getEnv() method just throws an exception with a message explaining that it is not supported.

However, an environment variable can be made available as a system property if it is defined as a system property on the command line that invokes the Java virtual machine. For example, to make the environment variable PRINTER available as a system property in a Windows environment, you can write:

C:\> java -Dprinter=%PRINTER%

In a UNIX environment, you can use:

% java -Dprinter=$PRINTER

Previous Home Next
System Properties Book Index External Program Execution

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java