Path Interface
Package: java.nio.file
The Path
interface defines an object that represents a file or directory path. Note that a Path
object doesn’t represent the file or directory indicated by the path; it represents the path to the file. The file or directory pointed to by a Path
object may or may not actually exist on disk.
Because Path
is an interface, not a class, it has no constructors. Of the many ways to create a Path
object, one of the most common is to use the get
method of the Paths
class. For more information, see Paths Class.
Path
objects can also be created by static members of the Files
class. For more information, see Files Class.
A Path
object can be thought of as a root component and a hierarchical sequence of distinct names separated by separator characters (usually backslashes). The root component identifies the file system being used; in a Windows system, this might be a drive letter. The sequence of names represents the directories needed to navigate through the file system to the target file or directory. The last name in the sequence represents the name of the target file or directory itself.
Methods
Method |
Description |
|
Returns the name of the target file or directory. |
|
Returns the name at the specified level in the path hierarchy. |
|
Returns the number of name elements in the path. |
|
Returns the root element of the path. |
|
Returns an |
|
Returns a |
|
Returns the string representation of the path. |