Maybe you can use Guava's Files.simplifyPath. Saves some lines...