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 System class getProperty method:
String homeDir = System.getProperty("user.home");
On my Mac OS X system, the String
homeDir now contains the following content: