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 @attacomsian on Twitter. You can also follow me on LinkedIn and DEV. Subscribe to RSS Feed.

👋 If you enjoy reading my articles and want to support me to continue creating free tutorials, Buy me a coffee (cost $3) .

Need help to launch a new product? I am available for contract work. Hire me to accomplish your business goals with engineering and design.