- java.lang.Object
-
- java.nio.file.Paths
-
-
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
. Ifmore
does not specify any elements then the value of thefirst
parameter is the path string to convert. Ifmore
specifies 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-separator
as 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
. APath
representing an empty path is returned iffirst
is the empty string andmore
does not contain any non-empty strings.The
Path
is obtained by invoking thegetPath
method of thedefault
FileSystem
.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 existingPath
instance 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 aPath
object.This method iterates over the
installed
providers to locate the provider that is identified by the URIscheme
of the given URI. URI schemes are compared without regard to case. If the provider is found then itsgetPath
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 thedefault
file system.The default provider provides a similar round-trip guarantee to the
File
class. For a givenPath
p it is guaranteed thatPaths.get(p.
so long as the originaltoUri
()).equals( p.toAbsolutePath
())Path
, theURI
, and the newPath
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
- if preconditions on theuri
parameter 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
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
25/11/2024 02:09:34 Cette version de la page est en cache (à la date du 25/11/2024 02:09:34) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 11/06/2005, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-java/nio/file/paths.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.