What's the best way to find the home directory of an arbitrary user in Java?
<p>What's the best way to find the home directory of an arbitrary user (not necessarily the one running the program) on a Unix-like system, given their username?</p>

<p>I'm looking to do something like this:</p>

<pre><code>public void writeToHomeDirectory(String user){
    File homeFolder = new File("~" + user);

    File f = new File(homeFolder, "A File");
    //f.writeStuff()
}
</code></pre>

<p>This doesn't work as the '~user' doesn't expand as this is a shell feature. Is there any way to do this in Java, or is the only way going to involve running a shell with Runtime.exec()?</p>
