Jan 172017

ADM

How to get the current working directory in Java

  • 17 January 2017
  • ADM

 

 

 

How to get the current working directory in Java - images/logos/java.jpg

 

Here is a simple example how to get the current working directory using the system property user.dir. The current working directory is the root folder of your current Java project or if you are running a jar file is the folder where is located.

Example

package com.admfactory.io;

public class CurrentDirectory {
    public static void main(String[] args) {
	System.out.println("Working Directory Example");
	System.out.println();
	String workingDir = System.getProperty("user.dir");
	System.out.println("Current working directory : " + workingDir);
    }
}

Output

Working Directory Example

Current working directory : D:\Repositories\Bitbucket\admfactory.com\JavaIO