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.


    public static void main(String[] args) {

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

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

Java Example - Get Current Working Directory

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap