Tag Archive For "system property"
Get the Current Working Directory in Java
How do you get the current working directory in Java? There are a few different ways of getting the the current working directory. System Property user.dir The System class contains properties that describes the configuration of the current working environment. The property that returns the current working directory is “user.dir”. String userDir = System.getProperty(“user.dir”);System.out.println(“The current …
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”);
Recent Comments