Java: toUri
URI toUri()
This method constructs an absolute URI
with a scheme
equal to the URI scheme that identifies the provider. The exact form of the scheme specific part is highly provider dependent.
In the case of the default provider, the URI is hierarchical with a path
component that is absolute. The query and fragment components are undefined. Whether the authority component is defined or not is implementation dependent. There is no guarantee that the URI
may be used to construct a java.io.File
. In particular, if this path represents a Universal Naming Convention (UNC) path, then the UNC server name may be encoded in the authority component of the resulting URI. In the case of the default provider, and the file exists, and it can be determined that the file is a directory, then the resulting URI
will end with a slash.
The default provider provides a similar round-trip guarantee to the File
class. For a given Path
p it is guaranteed that
so long as the originalPaths.get
(p.toUri()).equals(p .toAbsolutePath
())
Path
, the URI
, and the new Path
are all created in (possibly different invocations of) the same Java virtual machine. Whether other providers make any guarantees is provider specific and therefore unspecified.
When a file system is constructed to access the contents of a file as a file system then it is highly implementation specific if the returned URI represents the given path in the file system or it represents a compound URI that encodes the URI of the enclosing file system. A format for compound URIs is not defined in this release; such a scheme may be added in a future release.
Returns:
the URI representing this path
Throws:
IOError
- if an I/O error occurs obtaining the absolute path, or where a file system is constructed to access the contents of a file as a file system, and the URI of the enclosing file system cannot be obtained
SecurityException
- In the case of the default provider, and a security manager is installed, thetoAbsolutePath
method throws a security exception.