Java program to get current working directory

Here's a Java program to get the current working directory:

import java.io.File;

public class Main {
    public static void main(String[] args) {
        String currentDirectory = System.getProperty("user.dir");
        System.out.println("Current Working Directory: " + currentDirectory);
    }
}
Source:‮ww‬w.theitroad.com

This program uses the System.getProperty() method to get the current working directory. The argument to this method is the name of the property you want to retrieve, which in this case is "user.dir". This property contains the current working directory of the user's system.

We then print the current working directory to the console using System.out.println().

This program can be customized to perform additional file system operations, such as listing the contents of the current directory or creating a new file in the current directory.