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.
When I ran above program, I got below output:
Java program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
package org.arpit.java2blog; /* * @Author Arpit Mandliya */ public class getHomeDirectoryMain { public static void main(String[] args) { System.out.println("--------------"); String homeDirectory=""; homeDirectory = System.getProperty("user.home"); System.out.println("Home directory is : "+homeDirectory); System.out.println("--------------"); } } |
1 2 3 4 5 |
-------------- Home directory is : /Users/Arpit -------------- |
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.