Thursday, August 8, 2019

How to get the current user directory in a Java application

This tutorial explains how to get the current user directory in a Java application. You can determine the current directory your Java application is started in using System.getProperty() method and the user.dir property, like this:

How to get the current user directory in a Java application


String currentDirectory = System.getProperty("user.dir");

Here’s a complete example:
public class JavaCurrentDirectoryExample {
  public static void main(String[] args) {
    String currentDirectory = System.getProperty("user.dir");
    System.out.println("user.dir: " + currentDirectory);
  }
}

Output :-
----------------
D:\new project

This is all about How to get the current user directory in a Java application. Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section.

No comments:

Post a Comment