Class PathUtils

java.lang.Object
org.carrot2.util.PathUtils

public class PathUtils extends Object
This class defines utilities methods helping to determine path-related information such as relative paths.

The original code comes from org.codehaus.plexus.util.PathTool.

Author:
Ibrahim Chaehoi, Pete Kazmier, Vincent Massol, Vincent Siveton
  • Method Details

    • getRelativeFilePath

      public static final String getRelativeFilePath(String oldPath, String newPath)
      This method can calculate the relative path between two pathes on a file system.
       PathUtils.getRelativeFilePath( null, null )                                   = ""
       PathUtils.getRelativeFilePath( null, "/usr/local/java/bin" )                  = ""
       PathUtils.getRelativeFilePath( "/usr/local", null )                           = ""
       PathUtils.getRelativeFilePath( "/usr/local", "/usr/local/java/bin" )          = "java/bin"
       PathUtils.getRelativeFilePath( "/usr/local", "/usr/local/java/bin/" )         = "java/bin"
       PathUtils.getRelativeFilePath( "/usr/local/java/bin", "/usr/local/" )         = "../.."
       PathUtils.getRelativeFilePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "java/bin/java.sh"
       PathUtils.getRelativeFilePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = "../../.."
       PathUtils.getRelativeFilePath( "/usr/local/", "/bin" )                        = "../../bin"
       PathUtils.getRelativeFilePath( "/bin", "/usr/local/" )                        = "../usr/local"
       
      Note: On Windows based system, the / character should be replaced by \ character.
      Parameters:
      oldPath - the old path
      newPath - the new path
      Returns:
      a relative file path from oldPath.