Java Get Current Working Directory

Amir
Amir
Java Get Current Working Directory

How to get the current working directory in Java? The current working directory means the root folder of your current Java project.

We can get the current working directory in Java using the following system property function:

1
String cwd = System.getProperty("user.dir");

Get Current Working Directory in Java Example

1
2
3
4
5
6
7
8
9
public class CurrentWorkingDirectory {

    public static void main (String args[]) {

        String cwd = System.getProperty("user.dir");
        System.out.println("Current working directory : " + cwd);

    }
}

Output:

1
Current working directory: C:\workspace\Java4Testers
See also