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:

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

Get Current Working Directory in Java Example

public class CurrentWorkingDirectory {

    public static void main (String args[]) {

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

    }
}

Output:

Current working directory: C:\workspace\Java4Testers