How to get current directory in Java?

To get current directory in Java, do this: System.getProperty("user.dir").

System.getProperty("user.dir") returns the directory in which the Java Virtual Machine was invoked:

System.out.println(System.getProperty("user.dir")); // e.g. /Users/whaadev/Projects/testing-current-directory

Also known as the current working directory.