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");

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

Leave a Reply