Java - Current Working Directory

Introduction

You can get the current working directory for the JVM by reading the user.dir system property.

String workingDir = System.getProperty("user.dir");

Demo

public class Main {
  public static void main(String[] args) throws Exception {
    String workingDir = System.getProperty("user.dir");
    System.out.println(workingDir);
  }//from w ww  .j a  v  a  2 s. co m
}

Result

To specify the current working directory for the JVM as the user.dir property value as a JVM option.

java -Duser.dir=C:\test your-java-class

Related Topic