List of utility methods to do Path Relative nio
String | getRelativePath(File root, File f) get Relative Path Path fPath = f.toPath().toAbsolutePath(); Path rootPath = root.toPath().toAbsolutePath(); if (fPath.startsWith(rootPath)) { return fPath.toString().substring(rootPath.toString().length() + 1); } else { throw new IllegalStateException(fPath + " must be located inside " + rootPath); |
Path | getRelativePath(final File file, final File baseDir) Gets the relative from the specified directory to the specified file. final Path fileDirPath = file.toPath(); final Path baseDirPath = baseDir.toPath(); return baseDirPath.relativize(fileDirPath); |
String | getRelativePath(Path file, Path baseDir) get Relative Path return getRelativePath(file != null ? file.toString() : null, baseDir != null ? baseDir.toString() : null);
|
String | getRelativePath(Path rootPath, Path path) Gets the relative path based on a root path and a target path. String relativePath = ""; String r = rootPath.toString().trim(); String p = path.toString().trim(); if (!p.equalsIgnoreCase(r) && p.startsWith(r)) { relativePath = path.subpath(rootPath.getNameCount(), path.getNameCount()).toString(); return relativePath; |
String | getRelativePath(String file, String directory) get Relative Path Path pathAbsolute = Paths.get(file);
Path pathBase = Paths.get(directory);
Path pathRelative = pathBase.relativize(pathAbsolute);
return pathRelative.toString();
|
String | getRelativePath(String fullPath, String homeFolderPath) Return the path of the folder as in the database entry of the file String parentPath = ""; try { URL parentURL = Paths.get(fullPath).toUri().toURL(); URL homeFolderURL = Paths.get(homeFolderPath).toUri().toURL(); parentPath = parentURL.getPath().replace(homeFolderURL.getPath(), ""); parentPath = URLDecoder.decode(parentPath, "UTF-8"); if (parentPath.length() > 0 && parentPath.charAt(parentPath.length() - 1) == '/') { parentPath = parentPath.substring(0, parentPath.length() - 1); ... |
String | getRelativePath(String relativePathFile) get Relative Path Path path = Paths.get(relativePathFile);
return path.getFileName().toFile().getAbsolutePath();
|
Path | getSourceFileRelativePath(Class> declaringClass) get Source File Relative Path Path packageRelativePath = transformIntoPath(declaringClass);
String declaringFileName = getSourceFileName(declaringClass);
return packageRelativePath.resolve(declaringFileName);
|
boolean | isRelativePath(Path baseDir, Path file) is Relative Path return file.startsWith(baseDir);
|
boolean | isRelativized(final Path base, final String successor) is Relativized return isRelativized(base, Paths.get(successor));
|