Path getRoot() method in Java with Examples
The Java Path interface was added to Java NIO in Java 7. The Path interface is located in the java.nio.file package, so the fully qualified name of the Java Path interface is java.nio.file.Path. A Java Path instance represents a path in the file system. A path can use to locate either a file or a directory.path of an entity could be of two types one is an absolute path and other is a relative path. The absolute path is the location address from the root to the entity while the relative path is the location address which is relative to some other path.
getRoot() method of java.nio.file.Path used to return path object of the root component of this path object or null if this path does not have a root component.
Parameters: This method accepts nothing.
Return value: This method returns a path representing the root component of this path, or null.
Below programs illustrate getRoot() method: