# How to get the current working directory in Java

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Dec 15, 2019, updated Oct 8, 2022. Topics: Java.
Canonical URL: https://attacomsian.com/blog/java-get-current-working-directory

> A quick hack to learn how to get current working directory in Java.

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

```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:

```java
// 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:

* [Reading and Writing Files in Java](https://attacomsian.com/blog/java-read-write-files)
* [How to Read and Write Text Files in Java](https://attacomsian.com/blog/java-read-write-text-files)
* [How to Read and Write Binary Files in Java](https://attacomsian.com/blog/java-read-write-binary-files)
* [Reading and Writing Files using Java NIO API](https://attacomsian.com/blog/java-read-write-files-nio-api)
* [How to read a file line by line in Java](https://attacomsian.com/blog/how-to-read-a-file-line-by-line-in-java)
