Find User Home Directory in Java

The System class maintains a Properties object that describes the configuration of the current working environment. Within these properties there exists one that identifies the users home directory. In most scenarios this will work, but note that in some it might not work. I refer to BUG 4787931.

By using the system property user.home we get the location of the home directory.

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

Finding The Home Directory

package com.memorynotfound.file;

public class FindUserHomeDirectory {

    public static void main(String... args){
        String home = System.getProperty("user.home");
        System.out.println("User Home Directory: " + home);

Generated Output

User Home Directory: /Users/sipsoli


You may also like...