Java Path Relative Get getRelativePath(String basePath, String path)

Here you can find the source of getRelativePath(String basePath, String path)

Description

Get the relative path from the canoical basepath and path.

License

Open Source License

Parameter

Parameter Description
basePath a parameter
path a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static String getRelativePath(String basePath, String path) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

public class Main {
    /**// w  w w .  j a  va2s .c  o m
     * Get the relative path from the canoical basepath and path. 
     * 
     * @param basePath
     * @param path
     * @return
     * @throws IOException
     */
    public static String getRelativePath(String basePath, String path) throws IOException {
        if (basePath == null || path == null || basePath.equalsIgnoreCase(path))
            return "";
        else if (path.startsWith(basePath)) {
            String relPath = path.substring(basePath.length(), path.length());
            return "." + relPath;
        }
        return "";
    }
}

Related

  1. getRelativePath(final File parentDirectory, final File file)
  2. getRelativePath(final String base, final File targetFile)
  3. getRelativePath(String base, String fullPath)
  4. getRelativePath(String base, String relative, boolean isBaseFile)
  5. getRelativePath(String baseFullPath, File file)
  6. getRelativePath(String basePath, String pathToRelativize)
  7. getRelativePath(String fileName, String projFile)
  8. getRelativePath(String filePath, String basePath)
  9. getRelativePath(String from, String to)