Java properties FAQ: In Java, how do I determine a user’s home directory?
Answer: I often need to do this when creating Java/Swing GUI applications. Fortunately it's simple (once you know how to do it), just use a line of code like this, using the Java
String homeDir = System.getProperty("user.home");
On my Mac OS X system, the String
homeDir now contains the following content:
Other Java system property examples
Of course the trick to this is knowing that there is a property named
user.home. To see all the other Java system properties that are available to you, please refer to my "How to list all the Java system properties" tutorial.