You could use JDK7 Path api which is much friendlier for cases like this