How to get home directory in java

In this post, we will see how to get user profile's home directory in java. It is quite simple, we can use System.getProperty("user.home") to get it.

Java program:

package org.arpit.java2blog;

 * @Author Arpit Mandliya
public class getHomeDirectoryMain {

	public static void main(String[] args)
		String homeDirectory="";
		homeDirectory = System.getProperty("user.home");
		System.out.println("Home directory is : "+homeDirectory);

When I ran above program, I got below output:
Home directory is : /Users/Arpit

Written by Arpit:

If you have read the post and liked it. Please connect with me on Facebook | Twitter | Google Plus


Java tutorial for beginners Copyright © 2012