- java.lang.Object
-
- java.nio.file.Paths
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Pathget(String first, String... more)Converts a path string, or a sequence of strings that when joined form a path string, to aPath.static Pathget(URI uri)Converts the given URI to aPathobject.
-
-
-
Method Detail
-
get
public static Path get(String first, String... more)
Converts a path string, or a sequence of strings that when joined form a path string, to aPath. Ifmoredoes not specify any elements then the value of thefirstparameter is the path string to convert. Ifmorespecifies one or more elements then each non-empty string, includingfirst, is considered to be a sequence of name elements (seePath) and is joined to form a path string. The details as to how the Strings are joined is provider specific but typically they will be joined using thename-separatoras the separator. For example, if the name separator is "/" andgetPath("/foo","bar","gus")is invoked, then the path string"/foo/bar/gus"is converted to aPath. APathrepresenting an empty path is returned iffirstis the empty string andmoredoes not contain any non-empty strings.The
Pathis obtained by invoking thegetPathmethod of thedefaultFileSystem.Note that while this method is very convenient, using it will imply an assumed reference to the default
FileSystemand limit the utility of the calling code. Hence it should not be used in library code intended for flexible reuse. A more flexible alternative is to use an existingPathinstance as an anchor, such as:Path dir = ... Path path = dir.resolve("file");- Parameters:
first- the path string or initial part of the path stringmore- additional strings to be joined to form the path string- Returns:
- the resulting
Path - Throws:
InvalidPathException- if the path string cannot be converted to aPath- See Also:
FileSystem.getPath(java.lang.String, java.lang.String...)
-
get
public static Path get(URI uri)
Converts the given URI to aPathobject.This method iterates over the
installedproviders to locate the provider that is identified by the URIschemeof the given URI. URI schemes are compared without regard to case. If the provider is found then itsgetPathmethod is invoked to convert the URI.In the case of the default provider, identified by the URI scheme "file", the given URI has a non-empty path component, and undefined query and fragment components. Whether the authority component may be present is platform specific. The returned
Pathis associated with thedefaultfile system.The default provider provides a similar round-trip guarantee to the
Fileclass. For a givenPathp it is guaranteed that
so long as the originalPaths.get(p.toUri()).equals(p.toAbsolutePath())Path, theURI, and the newPathare all created in (possibly different invocations of) the same Java virtual machine. Whether other providers make any guarantees is provider specific and therefore unspecified.- Parameters:
uri- the URI to convert- Returns:
- the resulting
Path - Throws:
IllegalArgumentException- if preconditions on theuriparameter do not hold. The format of the URI is provider specific.FileSystemNotFoundException- The file system, identified by the URI, does not exist and cannot be created automatically, or the provider identified by the URI's scheme component is not installedSecurityException- if a security manager is installed and it denies an unspecified permission to access the file system
-
-