A system properties named user.dir
can be used if you want to find the current working directory of your Java program.
package org.kodejava.io;
public class CurrentDirectoryExample {
public static void main(String[] args) {
// System property key to get current working directory.
String USER_DIR_KEY = "user.dir";
String currentDir = System.getProperty(USER_DIR_KEY);
System.out.println("Working Directory: " + currentDir);
}
}
Result example:
Working Directory: F:\Wayan\Kodejava\kodejava-example
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024