A simple path = path.replaceFirst("^~", System.getProperty("user.home"));
when it is gotten from the user (before making a File
out of it) should be enough to work in most cases – because the tilde is only expanded to a home directory if it is the first character in a directory section of a path.