public final class PathUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
collapseDots(java.lang.String path)
Removes all ../ and ./ entries from within the given path.
|
static java.lang.String |
makeAbsolute(java.lang.String path)
Converts the given path into an absolute one.
|
static java.lang.String |
makeAbsolute(java.lang.String path,
java.lang.String rootPath)
Converts the given path into an absolute one.
|
static java.lang.String |
makeRelative(java.lang.String basePath,
java.lang.String targetPath)
Returns targetPath relative to basePath.
|
public static java.lang.String collapseDots(java.lang.String path)
path
- The path to remove dots from.public static java.lang.String makeAbsolute(java.lang.String path)
Unlike File.getAbsolutePath(), this function does remove .'s from the path and unlike File.getCanonicalPath(), this function does not resolve symlinks and does not use filesystem calls.
path
- The path to make absolute.public static java.lang.String makeAbsolute(java.lang.String path, java.lang.String rootPath)
Unlike File.getAbsolutePath(), this function does remove .'s from the path and unlike File.getCanonicalPath(), this function does not resolve symlinks and does not use filesystem calls.
rootPath
- The path to prefix to path if path is not already absolute.path
- The path to make absolute.public static java.lang.String makeRelative(java.lang.String basePath, java.lang.String targetPath)
basePath and targetPath must either both be relative, or both be absolute paths.
This function is different from makeRelative in that it is able to add in ../ components and collapse existing ones as well.
Examples: base="some/relative/path" target="some/relative/path/foo" return="foo" base="some/relative/path" target="some/relative" return=".." base="some/relative/path" target="foo/bar" return="../../../foo/bar" base="/some/abs/path" target="/foo/bar" return="../../../foo/bar"basePath
- The path to make targetPath relative to.targetPath
- The path to make relative.Copyright © 2009-2020 Google. All Rights Reserved.