java

How to get the current working directory in Java

In this tutorial, we are going to see how to get the current directory in Java. The current directory means the root folder of your current Java project.

We can get the current directory in Java using the getProperty() method of the System class.
 

How to get the current working directory in Java
public class Main {

    public static void main (String args[]) {

        String pwd = System.getProperty("user.dir");
        System.out.println("The current directory is : " + pwd);

    }
}

Output:

The current directory is : C:\Users\waytolearnx\Desktop\app
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *