Get Current Working Directory in Java
You can retrieve the current working directory by calling System.getProperty("user.dir")
.
This returns the root folder of your current java project.
Example
package com.memorynotfound.file;
import java.io.File;
public class FindCurrentWorkingDirectory {
public static void main(String... args){
String currentWorkingDir = System.getProperty("user.dir");
System.out.println("Current working directory: " + currentWorkingDir);
}
}
Current working directory: /Users/memorynotfound/tutorials/java
Current working directory: /Users/memorynotfound/tutorials/java