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 create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023