Accessing “~” (user home) from Java in Linux

The ~ notation is a shell thing. Read up on shell expansion.

Java doesn’t understand this notation. To get hold of the home directory, get the system property with key user.home:

String home = System.getProperty("user.home");
File f = new File(home + "/.config/gfgd.gfgdf");

(As a bonus, it will work on windows machines too 😉

Leave a Comment

tech