Showing posts with label nio. Show all posts

How to get current working directory path in Java?

Following excerpt show how to get current working directory path in Java using java.nio.file.Path (Java 7 or up).

Source code (
import java.nio.file.Path;
import java.nio.file.Paths;

 * Get current working directory path.
 * @author javaQuery
 * @date 27th December, 2016
 * @Github:
public class CurrentWorkingDirectory {

    public static void main(String[] args) {
        Path path = Paths.get("");
        String currentWorkingDirectory = path.toAbsolutePath().toString();
        System.out.println("Current working directory: " + currentWorkingDirectory);

Current working directory: C:\Users\Vicky\Documents\NetBeansProjects\Examples