java.io.ObjectInputValidation, java.io.Serializable, java.lang.Comparable<Path>@Stringable @Public @Stable public class Path extends java.lang.Object implements java.lang.Comparable<Path>, java.io.Serializable, java.io.ObjectInputValidation
FileSystem.
Path strings use slash as the directory separator.| Modifier and Type | Field | Description |
|---|---|---|
static java.lang.String |
CUR_DIR |
The current directory, ".".
|
static java.lang.String |
SEPARATOR |
The directory separator, a slash.
|
static char |
SEPARATOR_CHAR |
The directory separator, a slash, as a character.
|
static boolean |
WINDOWS |
Whether the current host is a Windows machine.
|
| Constructor | Description |
|---|---|
Path(java.lang.String pathString) |
Construct a path from a String.
|
Path(java.lang.String parent,
java.lang.String child) |
Create a new Path based on the child path resolved against the parent path.
|
Path(java.lang.String scheme,
java.lang.String authority,
java.lang.String path) |
Construct a Path from components.
|
Path(java.lang.String parent,
Path child) |
Create a new Path based on the child path resolved against the parent path.
|
Path(java.net.URI aUri) |
Construct a path from a URI
|
Path(Path parent,
java.lang.String child) |
Create a new Path based on the child path resolved against the parent path.
|
Path(Path parent,
Path child) |
Create a new Path based on the child path resolved against the parent path.
|
| Modifier and Type | Method | Description |
|---|---|---|
int |
compareTo(Path o) |
|
int |
depth() |
Returns the number of elements in this path.
|
boolean |
equals(java.lang.Object o) |
|
FileSystem |
getFileSystem(Configuration conf) |
Return the FileSystem that owns this Path.
|
java.lang.String |
getName() |
Returns the final component of this path.
|
java.util.Optional<Path> |
getOptionalParentPath() |
Returns the parent of a path as
Optional or
Optional.empty() i.e an empty Optional if at root. |
Path |
getParent() |
Returns the parent of a path or null if at root.
|
static Path |
getPathWithoutSchemeAndAuthority(Path path) |
Return a version of the given Path without the scheme information.
|
int |
hashCode() |
|
boolean |
isAbsolute() |
Returns true if the path component (i.e.
|
boolean |
isAbsoluteAndSchemeAuthorityNull() |
Returns true if the path component (i.e.
|
boolean |
isRoot() |
Returns true if and only if this path represents the root of a file system.
|
boolean |
isUriPathAbsolute() |
Returns true if the path component (i.e.
|
static boolean |
isWindowsAbsolutePath(java.lang.String pathString,
boolean slashed) |
Determine whether a given path string represents an absolute path on
Windows.
|
Path |
makeQualified(java.net.URI defaultUri,
Path workingDir) |
Returns a qualified path object.
|
Path |
makeQualified(FileSystem fs) |
Deprecated.
|
static Path |
mergePaths(Path path1,
Path path2) |
Merge 2 paths such that the second path is appended relative to the first.
|
Path |
suffix(java.lang.String suffix) |
Adds a suffix to the final name in the path.
|
java.lang.String |
toString() |
|
java.net.URI |
toUri() |
Convert this Path to a URI.
|
void |
validateObject() |
Validate the contents of a deserialized Path, so as
to defend against malicious object streams.
|
public static final java.lang.String SEPARATOR
public static final char SEPARATOR_CHAR
public static final java.lang.String CUR_DIR
public static final boolean WINDOWS
public Path(java.lang.String parent,
java.lang.String child)
parent - the parent pathchild - the child pathpublic Path(Path parent, java.lang.String child)
parent - the parent pathchild - the child pathpublic Path(java.lang.String parent,
Path child)
parent - the parent pathchild - the child pathpublic Path(Path parent, Path child)
parent - the parent pathchild - the child pathpublic Path(java.lang.String pathString)
throws java.lang.IllegalArgumentException
pathString - the path stringjava.lang.IllegalArgumentExceptionpublic Path(java.net.URI aUri)
aUri - the source URIpublic Path(java.lang.String scheme,
java.lang.String authority,
java.lang.String path)
scheme - the schemeauthority - the authoritypath - the pathpublic static Path getPathWithoutSchemeAndAuthority(Path path)
path - the source Pathpublic static Path mergePaths(Path path1, Path path2)
path1 - the first pathpath2 - the second path, to be appended relative to path1public static boolean isWindowsAbsolutePath(java.lang.String pathString,
boolean slashed)
pathString - the path string to evaluateslashed - true if the given path is prefixed with "/"public java.net.URI toUri()
public FileSystem getFileSystem(Configuration conf) throws java.io.IOException
conf - the configuration to use when resolving the FileSystemjava.io.IOException - thrown if there's an issue resolving the
FileSystempublic boolean isAbsoluteAndSchemeAuthorityNull()
public boolean isUriPathAbsolute()
public boolean isAbsolute()
isUriPathAbsolute().public boolean isRoot()
public java.lang.String getName()
public Path getParent()
getOptionalParentPath() to handle nullable value for root path.public java.util.Optional<Path> getOptionalParentPath()
Optional or
Optional.empty() i.e an empty Optional if at root.Optional.
Optional.empty() i.e an empty Optional if at root.public Path suffix(java.lang.String suffix)
suffix - the suffix to addpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic int compareTo(Path o)
compareTo in interface java.lang.Comparable<Path>public int depth()
@Deprecated public Path makeQualified(FileSystem fs)
FileSystem's working
directory.fs - the target FileSystem@LimitedPrivate({"HDFS","MapReduce"})
public Path makeQualified(java.net.URI defaultUri,
Path workingDir)
defaultUri - if this path is missing the scheme or authority
components, borrow them from this URIworkingDir - if this path isn't absolute, treat it as relative to this
working directorypublic void validateObject()
throws java.io.InvalidObjectException
validateObject in interface java.io.ObjectInputValidationjava.io.InvalidObjectException - if there's no URICopyright © 2008–2025 Apache Software Foundation. All rights reserved.