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
-

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


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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