What is the purpose of user.dir in Java?
user.dir is one of the Java system properties, used to retrieve the path of the current working directory.
In a Java program, you can use System.getProperty(“user.dir”) to retrieve the path of the current working directory, where the program is currently running. This property is typically used to specify the relative path of a file when reading or writing, so that the program can locate the file correctly.
For example, if the current working directory is /Users/username/Documents, then System.getProperty(“user.dir”) will return /Users/username/Documents.