Search code examples
javaniojava.nio.file

Is System.getProperty("user.home") equivalent to Paths.get("~").absolutePath?


By equivalence, i mean logical equivalence, not the String comparison. E.g. if I do Files.newBufferedReader(Paths.get("file.txt", System.getProperty("user.home")) and Files.newBufferedReader(Paths.get("~").resolve(Paths.get("file.txt"))), will I get the same file on Windows and other systems?


Solution

  • Of course no. Tilde character has special meaning in shell. It points to HOME variable. In Java ~ is like any other file name. In addition in Windows you cannot use ~ as home directory equivalent.