How to get current working directory in java

In this post, we will see how to get current working directory in java.
There are two ways to do it.

  • Using property user.dir
  • Using getAbsolutePath()

Using property user.dir

We can use System.getProperty(“user.dir”) to get current working directory path.

When I ran above program, I got below output:

Using getAbsolutePath()

We can use file.getAbos

When I ran above program, I got below output:

Add Comment