Java Program to Get Current Working Directory

Java Programming Java8Object Oriented Programming

The java.lang.System.getProperty(String key) method gets the system property indicated by the specified key. You can get the current directory path bypassing the string value "user.dir" to this method.

Example

Live Demo

public class Main {
   public static void main(String[] args) {
      String curDir = System.getProperty("user.dir");
      System.out.println("You currently working in :" + curDir+ ": Directory");
   }
}

Output

You currently working in :C:\Documents and Settings\user\
My Documents\NetBeansProjects\TestApp: Directory
raja
Published on 26-Apr-2018 11:16:31
Advertisements