Archive for the tag 'system property'

Aug 21 2009

How to read environment variables in Java

Published by under 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”);

No responses yet

Aug 03 2009

Java and the current work directory

Published by under Java

I spent some time looking this up and hopefully I will save someone else time on this. The current work directory for an application in Java is stored in the system property “user.dir”. This is the default directory that you application will write files to if you don’t specify an absolute file location. You can […]

No responses yet