Path: blob/master/src/java.base/share/classes/java/nio/file/Paths.java
41159 views
/*1* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.nio.file;2627import java.nio.file.spi.FileSystemProvider;28import java.net.URI;2930/**31* This class consists exclusively of static methods that return a {@link Path}32* by converting a path string or {@link URI}.33*34* @apiNote35* It is recommended to obtain a {@code Path} via the {@code Path.of} methods36* instead of via the {@code get} methods defined in this class as this class37* may be deprecated in a future release.38*39* @since 1.740* @see Path41*/4243public final class Paths {44private Paths() { }4546/**47* Converts a path string, or a sequence of strings that when joined form48* a path string, to a {@code Path}.49*50* @implSpec51* This method simply invokes {@link Path#of(String,String...)52* Path.of(String, String...)} with the given parameters.53*54* @param first55* the path string or initial part of the path string56* @param more57* additional strings to be joined to form the path string58*59* @return the resulting {@code Path}60*61* @throws InvalidPathException62* if the path string cannot be converted to a {@code Path}63*64* @see FileSystem#getPath65* @see Path#of(String,String...)66*/67public static Path get(String first, String... more) {68return Path.of(first, more);69}7071/**72* Converts the given URI to a {@link Path} object.73*74* @implSpec75* This method simply invokes {@link Path#of(URI) Path.of(URI)} with the76* given parameter.77*78* @param uri79* the URI to convert80*81* @return the resulting {@code Path}82*83* @throws IllegalArgumentException84* if preconditions on the {@code uri} parameter do not hold. The85* format of the URI is provider specific.86* @throws FileSystemNotFoundException87* The file system, identified by the URI, does not exist and88* cannot be created automatically, or the provider identified by89* the URI's scheme component is not installed90* @throws SecurityException91* if a security manager is installed and it denies an unspecified92* permission to access the file system93*94* @see Path#of(URI)95*/96public static Path get(URI uri) {97return Path.of(uri);98}99}100101102