Get user home directory name in Java

Description

The following code shows how to get user home directory name.

Example


//from ww w.j a  v a2 s  .c  om
public class Main {
  public static void main(String[] args) {
    String userHome = "user.home";

    String path = System.getProperty(userHome);

    System.out.println("Your Home Path: " + path);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip