In Java 7 and higher, you can use Paths.get() method to get the current working directory in Java:

// get current working directory
String cwd = Paths.get("").toAbsolutePath().toString();

// print cwd
System.out.println(cwd);

Alternatively, you can also use System.getProperty("user.dir") to get the current working directory:

// get current working directory
String cwd = System.getProperty("user.dir");

// print cwd
System.out.println(cwd);

Further Reading

You may be interested in other Java I/O articles:

✌️ Like this article? Follow me on Twitter and LinkedIn. You can also Subscribe to RSS Feed.

Last Updated: