- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AzureFilePath,FTPPath,GcpFilePath,HadoopFilePath
Path represents a location
in a FileSystem. Paths are normally constructed via the methods
available in Paths.
Paths present a hierarchical structure for locating resources, identifying a
resource based on a sequential traversal of elements, typically starting from
some root. The methods of this interface deal only with the structural
aspects of paths, not with the data which they identified. To actually access
the data represented by a path, use the methods found in FileClient.
Paths are identified using a URI-like syntax, using a scheme prefix of
file
scheme is recognized, a scheme is not required; path strings with no scheme
are assumed to be local files. Some examples of path strings are:
file:/home/myuser/myfile C:\temp\myfile ../siblingfile hdfs://namenode:9000/path/to/file
It is only necessary to implement a Path if writing a new file system
scheme, in which case it is necessary to also implement a
FileSystemProvider and FileSystem as well.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanGets the file system provider for this path.getName()Gets the last element of the path.Gets the path referring to the location containing the path.inthashCode()booleanIndicates whether the path is absolute or relative.Adds additional elements to the path.Converts a relative path into an absolute path.toFile()Gets the local file corresponding to the path.toString()Gets the string representation of the path.toURL()Returns the URL string corresponding to this path.
-
Method Details
-
getFileSystemProvider
FileSystemProvider getFileSystemProvider()Gets the file system provider for this path.- Returns:
- the file system provider associated with the path
-
isAbsolute
boolean isAbsolute()Indicates whether the path is absolute or relative. That is, does the path start from the root of the associated file system.For most file systems, all paths are absolute.
- Returns:
trueif the path starts from the file system root,falseotherwise.
-
toAbsolutePath
Path toAbsolutePath()Converts a relative path into an absolute path.- Returns:
- the absolute path pointing to the same location. If the path is already absolute, it is returned.
-
getParent
Path getParent()Gets the path referring to the location containing the path.- Returns:
- the path to the container of this path,
nullif this path is the root.
-
getName
String getName()Gets the last element of the path.- Returns:
- the last element of the path.
-
resolve
Adds additional elements to the path. The provided string is interpreted as a relative path starting from the path's location.- Parameters:
childPath- the- Returns:
- the resulting path
-
toFile
File toFile()Gets the local file corresponding to the path. This only makes sense when the path refers to the local file system. For other paths, it always returnsnull.- Returns:
- the file which this path identifies or
nullif it does not identify a file on the local file system.
-
toURL
String toURL()Returns the URL string corresponding to this path.- Returns:
- The URL string for this path, or
nullif this path cannot be mapped to a URL.
-
toString
String toString()Gets the string representation of the path. It must be true thatPaths.asPath(path.toString())refers to the same location aspath. However, it may not the case thatpathString.equals(Paths.asPath(pathString).toString()). -
equals
-
hashCode
int hashCode()
-