Java Utililty Methods Path Relative Get

List of utility methods to do Path Relative Get

Description

The list of methods to do Path Relative Get are organized into topic(s).

Method

StringgetRelativePath(String targetPath, String basePath, String pathSeparator)
get Relative Path
File f = new File(targetPath);
boolean isDir = f.isDirectory();
String[] base = basePath.split(Pattern.quote(pathSeparator), -1);
String[] target = targetPath.split(Pattern.quote(pathSeparator), 0);
String common = "";
int commonIndex = 0;
for (int i = 0; i < target.length && i < base.length; i++) {
    if (target[i].equals(base[i])) {
...
StringgetRelativePathOfZipEntry(final File fileToZip, final File base)
get Relative Path Of Zip Entry
String relativePathOfFile = fileToZip.getPath().substring(base.getPath().length() + 1);
if (File.separatorChar != '/') {
    relativePathOfFile = relativePathOfFile.replace(File.separatorChar, '/');
return relativePathOfFile;
StringgetRelativePathRecursive(File file, File baseDir, String prefix)
get Relative Path Recursive
if (isFileInDirRecursive(file, baseDir)) {
    return prefix + baseDir.toURI().relativize(file.toURI()).getPath();
} else if (baseDir.getParentFile() != null) {
    return prefix + getRelativePathRecursive(file, baseDir.getParentFile(), "../");
} else {
    return file.toURI().toString();
StringgetRelativePathToBase(File path, File basePath)
Returns the relative path of a path from a base path.
try {
    String dir = path.toURL().toExternalForm();
    String baseDir = basePath.toURL().toExternalForm();
    StringBuffer result = new StringBuffer();
    if (dir.indexOf(baseDir) == 0) {
        String delta = dir.substring(baseDir.length());
        for (int i = 0; i < delta.length(); i++) {
            if (delta.charAt(i) == '/') {
...
StringgetRelativePathToTestModule()
get Relative Path To Test Module
String relativePathToModule = "." + File.separator + "MainServer" + File.separator + "OurPlatformManager"
        + File.separator + "target" + File.separator + "TestModule-0.4-SNAPSHOT-mod.zip";
return relativePathToModule;
StringgetRelativePathToWWW(String fileName)
get Relative Path To WWW
return getRelativePathTo("www", fileName);