Path toAbsolutePath() method in Java with Examples
The Java Path interface was added to Java NIO in Java 7. toAbsolutePath() method of java.nio.file.Path used to return a Path object representing the absolute path of this path object. If the path is already absolute then the method returns path else this method resolves this path in an implementation-dependent manner by resolving the path against a file system default directory. Depending on the implementation, this method may throw an I/O error if the file system is not accessible.
Parameters: This method accepts nothing.
Return value: This method returns a Path object representing the absolute path.
Exception: This method throws following Exceptions:
- IOError – if an I/O error occurs
- SecurityException – In the case of the default provider, a security manager is installed, and this path is not absolute, then the security manager’s
- checkPropertyAccess method is invoked to check access to the system property user.dir
Below programs illustrate toAbsolutePath() method: