Paths (Java SE 10 & JDK 10 ) (original) (raw)
- java.nio.file.Paths
public final class Paths
extends Object
This class consists exclusively of static methods that return a Path by converting a path string or URI.
Since:
1.7
Method Summary
All Methods Static Methods Concrete Methods
Modifier and Type Method Description static Path get(String first,String... more) Converts a path string, or a sequence of strings that when joined form a path string, to a Path. static Path get(URI uri) Converts the given URI to a Path object. * ### Methods declared in class java.lang.[Object](../../../java/lang/Object.html "class in java.lang") `[clone](../../../java/lang/Object.html#clone%28%29), [equals](../../../java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../java/lang/Object.html#finalize%28%29), [getClass](../../../java/lang/Object.html#getClass%28%29), [hashCode](../../../java/lang/Object.html#hashCode%28%29), [notify](../../../java/lang/Object.html#notify%28%29), [notifyAll](../../../java/lang/Object.html#notifyAll%28%29), [toString](../../../java/lang/Object.html#toString%28%29), [wait](../../../java/lang/Object.html#wait%28%29), [wait](../../../java/lang/Object.html#wait%28long%29), [wait](../../../java/lang/Object.html#wait%28long,int%29)`
Method Detail
* #### get public static [Path](../../../java/nio/file/Path.html "interface in java.nio.file") get([String](../../../java/lang/String.html "class in java.lang") first, [String](../../../java/lang/String.html "class in java.lang")... more) Converts a path string, or a sequence of strings that when joined form a path string, to a `Path`. If `more` does not specify any elements then the value of the `first` parameter is the path string to convert. If `more` specifies one or more elements then each non-empty string, including `first`, is considered to be a sequence of name elements (see [Path](../../../java/nio/file/Path.html "interface in java.nio.file")) 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 the [name-separator](../../../java/nio/file/FileSystem.html#getSeparator%28%29) as the separator. For example, if the name separator is "`/`" and `getPath("/foo","bar","gus")` is invoked, then the path string `"/foo/bar/gus"` is converted to a `Path`. A `Path` representing an empty path is returned if `first` is the empty string and `more` does not contain any non-empty strings. The `Path` is obtained by invoking the [getPath](../../../java/nio/file/FileSystem.html#getPath%28java.lang.String,java.lang.String...%29) method of the [default](../../../java/nio/file/FileSystems.html#getDefault%28%29) [FileSystem](../../../java/nio/file/FileSystem.html "class in java.nio.file"). Note that while this method is very convenient, using it will imply an assumed reference to the default `FileSystem` and 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 existing `Path` instance as an anchor, such as: Path dir = ... Path path = dir.resolve("file"); Parameters: `first` \- the path string or initial part of the path string `more` \- additional strings to be joined to form the path string Returns: the resulting `Path` Throws: `[InvalidPathException](../../../java/nio/file/InvalidPathException.html "class in java.nio.file")` \- if the path string cannot be converted to a `Path` See Also: [FileSystem.getPath(java.lang.String, java.lang.String...)](../../../java/nio/file/FileSystem.html#getPath%28java.lang.String,java.lang.String...%29) * #### get public static [Path](../../../java/nio/file/Path.html "interface in java.nio.file") get([URI](../../../java/net/URI.html "class in java.net") uri) Converts the given URI to a [Path](../../../java/nio/file/Path.html "interface in java.nio.file") object. This method iterates over the [installed](../../../java/nio/file/spi/FileSystemProvider.html#installedProviders%28%29) providers to locate the provider that is identified by the URI [scheme](../../../java/net/URI.html#getScheme%28%29) of the given URI. URI schemes are compared without regard to case. If the provider is found then its [getPath](../../../java/nio/file/spi/FileSystemProvider.html#getPath%28java.net.URI%29) method 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 `Path` is associated with the[default](../../../java/nio/file/FileSystems.html#getDefault%28%29) file system. The default provider provides a similar _round-trip_ guarantee to the [File](../../../java/io/File.html "class in java.io") class. For a given `Path` _p_ it is guaranteed that > ` Paths.get(`_p_`.`[toUri](../../../java/nio/file/Path.html#toUri%28%29)`()).equals(` _p_`.`[toAbsolutePath](../../../java/nio/file/Path.html#toAbsolutePath%28%29)`())` so long as the original `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. Parameters: `uri` \- the URI to convert Returns: the resulting `Path` Throws: `[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if preconditions on the `uri` parameter do not hold. The format of the URI is provider specific. `[FileSystemNotFoundException](../../../java/nio/file/FileSystemNotFoundException.html "class in java.nio.file")` \- 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 installed `[SecurityException](../../../java/lang/SecurityException.html "class in java.lang")` \- if a security manager is installed and it denies an unspecified permission to access the file system
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2018, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.