Press enter to see results or esc to cancel.

How to read environment variables in Java

You can set environment variables or pass them in using the -Dvariablename syntax

SET logfile=/location/to/my/log/file.log

or

java -Dlogfile=/location/to/my/log/file.log HelloWorld

When you want to access these environment variables from your Java source file you can use

Java 1.5 and newer:

String logfileLocation = System.getenv("logfile");

Java 1.4 and older:

String logfileLocation = System.getProperty("logfile");