Thursday, August 8, 2019

How to get the current home directory in a Java application

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

How to get the current home directory in a Java application


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

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

This is all about how to get the current home 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