@Beta public final class Path extends Object
FileSystemSupport and MutableFileSystemSupport.
A path either starts with a slash which denotes an absolute path or a segment which denotes a relative path.
Note that this is an abstraction over different 'real' file systems and doesn't understand platform specific things like, e.g.
"c:/" on windows.
The path segment separator is '/'.| Modifier and Type | Field and Description |
|---|---|
static Path |
ROOT
the root path
|
static char |
SEGMENT_SEPARATOR
the segment separator used.
|
| Constructor and Description |
|---|
Path(String pathAsString)
Constructs a new Path object from a given string.
|
| Modifier and Type | Method and Description |
|---|---|
Path |
append(String suffix)
Appends the given suffix to this path.
|
boolean |
equals(Object obj) |
Path |
getAbsolutePath(Path relativePath) |
Path |
getAbsolutePath(String relativePath) |
String |
getFileExtension() |
String |
getLastSegment() |
Path |
getParent()
Returns the parent of this path or null if this path is the root path.
|
List<String> |
getSegments() |
int |
hashCode() |
boolean |
isAbsolute() |
Path |
relativize(Path other)
Constructs a relative path between this path and a given path.
|
Path |
relativize(String other)
See
relativize(Path) |
boolean |
startsWith(Path other)
Returns whether this path starts with the same segments and
has the same
isAbsolute() value. |
String |
toString() |
public static final char SEGMENT_SEPARATOR
public static final Path ROOT
public Path(String pathAsString)
pathAsString - public boolean isAbsolute()
public String getLastSegment()
public Path append(String suffix)
suffix - the suffix to append to this pathpublic Path getParent()
public String getFileExtension()
null if this path's last segment doesn't have a file extension.public Path getAbsolutePath(String relativePath)
relativePath - public Path getAbsolutePath(Path relativePath)
relativePath - public Path relativize(String other)
relativize(Path)other - a string representing a pathpublic Path relativize(Path other)
Relativization is the inverse of resolution.
This method attempts to construct a relative path
that when resolved against this path, yields a
path that locates the same file as the given path. For example, on UNIX,
if this path is "/a/b" and the given path is "/a/b/c/d"
then the resulting relative path would be "c/d".
Both paths must be absolute and and either this path or the given path must be a
prefix of the other.
other - the path to relativize against this pathIllegalArgumentException - if this path and other are not both absolute or relativepublic boolean startsWith(Path other)
isAbsolute() value.other - the path, which might be a prefix of this pathCopyright © 2015. All Rights Reserved.