In Java 7 and higher, you can use the Paths.get() method to get the current working directory in Java:
// get the 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 the 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: