public class PathTool extends Object
Constructor and Description |
---|
PathTool() |
Modifier and Type | Method and Description |
---|---|
static String |
getRelativeFilePath(String oldPath,
String newPath)
This method can calculate the relative path between two pathes on a file system.
|
static String |
getRelativePath(String basedir,
String filename)
Determines the relative path of a filename from a base directory.
|
public static String getRelativePath(@Nullable String basedir, @Nullable String filename)
$relativePath
context variable. The arguments to
this method may contain either forward or backward slashes as
file separators. The relative path returned is formed using
forward slashes as it is expected this path is to be used as a
link in a web page (again mimicking Anakia's behavior).
This method is thread-safe.
PathTool.getRelativePath( null, null ) = "" PathTool.getRelativePath( null, "/usr/local/java/bin" ) = "" PathTool.getRelativePath( "/usr/local/", null ) = "" PathTool.getRelativePath( "/usr/local/", "/usr/local/java/bin" ) = ".." PathTool.getRelativePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "../.." PathTool.getRelativePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = ""
basedir
- The base directory.filename
- The filename that is relative to the base
directory.basedir
is null or zero-length,
or filename
is null or zero-length.public static String getRelativeFilePath(String oldPath, String newPath)
PathTool.getRelativeFilePath( null, null ) = "" PathTool.getRelativeFilePath( null, "/usr/local/java/bin" ) = "" PathTool.getRelativeFilePath( "/usr/local", null ) = "" PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin" ) = "java/bin" PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin/" ) = "java/bin" PathTool.getRelativeFilePath( "/usr/local/java/bin", "/usr/local/" ) = "../.." PathTool.getRelativeFilePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "java/bin/java.sh" PathTool.getRelativeFilePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = "../../.." PathTool.getRelativeFilePath( "/usr/local/", "/bin" ) = "../../bin" PathTool.getRelativeFilePath( "/bin", "/usr/local/" ) = "../usr/local"Note: On Windows based system, the
/
character should be replaced by \
character.oldPath
- old pathnewPath
- new patholdPath
.Copyright © 2002–2016 The Apache Software Foundation. All rights reserved.