Java Program to Get Current Working Directory



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
Lakshmi Srinivas
Lakshmi Srinivas

Programmer / Analyst / Technician


Advertisements