Get the Current Working Directory using Java Code

We can make use of the System.getProperty() method to get the current working directory using Java code.


Example:

    public static void main(String[] args) {

        String currentWorkingDirectory = System.getProperty("user.dir");
        System.out.println("The Current Working Directory: " + currentWorkingDirectory);
 
   }
Output:

The Current Working Directory: /user/c2c/Desktop/java/

Java Example - Get Current Working Directory

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!