How to get the current working directory in Java?

Code :

public class JavaApplication {
  public static void main(String[] args) {
    System.out.println("Working Directory = " + System.getProperty("user.dir"));

This will print the absolute path of the current directory from where your application was initialized.


From the documentation: package resolve relative pathnames using current user directory. The current directory is represented as system property, that is, user.dir and is the directory from where the JVM was invoked.

Leave a Comment