import java.io.InputStreamReader;\r
import java.io.OutputStreamWriter;\r
import java.nio.charset.Charset;\r
+import java.nio.file.Path;\r
+import java.nio.file.Paths;\r
\r
/**\r
* Common file utilities.\r
* @return a relative path from basePath to path\r
*/\r
public static String getRelativePath(File basePath, File path) {\r
- File exactBase = getExactFile(basePath);\r
- File exactPath = getExactFile(path);\r
- if (path.getAbsolutePath().startsWith(basePath.getAbsolutePath())) {\r
- // absolute base-path match\r
- return StringUtils.getRelativePath(basePath.getAbsolutePath(), path.getAbsolutePath());\r
- } else if (exactPath.getPath().startsWith(exactBase.getPath())) {\r
- // canonical base-path match\r
- return StringUtils.getRelativePath(exactBase.getPath(), exactPath.getPath());\r
- } else if (exactPath.getPath().startsWith(basePath.getAbsolutePath())) {\r
- // mixed path match\r
- return StringUtils.getRelativePath(basePath.getAbsolutePath(), exactPath.getPath());\r
- } else if (path.getAbsolutePath().startsWith(exactBase.getPath())) {\r
- // mixed path match\r
- return StringUtils.getRelativePath(exactBase.getPath(), path.getAbsolutePath());\r
+ Path exactBase = Paths.get(getExactFile(basePath).toURI());\r
+ Path exactPath = Paths.get(getExactFile(path).toURI());\r
+ if (exactPath.startsWith(exactBase)) {\r
+ return exactBase.relativize(exactPath).toString();\r
}\r
// no relative relationship\r
return null;\r