# Get the Current Working Directory in Java

Java 8Object Oriented ProgrammingProgramming

#### Complete Java Programming Fundamentals With Sample Projects

98 Lectures 7.5 hours

#### Get your Java dream job! Beginners interview preparation

85 Lectures 6 hours

#### Core Java bootcamp program with Hands on practice

Featured

99 Lectures 17 hours

The method java.lang.System.getProperty() is used to obtain the system property. This system property is specified by the key which is the parameter for the method. To obtain the current working directory, the key used is user.dir.

A program that demonstrates this is given as follows −

## Example

Live Demo

public class Demo {
public static void main(String[] argv) throws Exception {
String currentDirectory = System.getProperty("user.dir");
System.out.println("The current working directory is " + currentDirectory);
}
}

The output of the above program is as follows −

## Output

The current working directory is c:\JavaProgram

Now let us understand the above program.

The current working directory is obtained by using the key user.dir with the method java.lang.System.getProperty(). Then the current working directory is printed. A code snippet that demonstrates this is given as follows −

String currentDirectory = System.getProperty("user.dir");
System.out.println("The current working directory is " + currentDirectory);
Updated on 30-Jul-2019 22:30:25