Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/nio/file/Path.java
38918 views
/*1* Copyright (c) 2007, 2013, 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.io.File;28import java.io.IOException;29import java.net.URI;30import java.util.Iterator;3132/**33* An object that may be used to locate a file in a file system. It will34* typically represent a system dependent file path.35*36* <p> A {@code Path} represents a path that is hierarchical and composed of a37* sequence of directory and file name elements separated by a special separator38* or delimiter. A <em>root component</em>, that identifies a file system39* hierarchy, may also be present. The name element that is <em>farthest</em>40* from the root of the directory hierarchy is the name of a file or directory.41* The other name elements are directory names. A {@code Path} can represent a42* root, a root and a sequence of names, or simply one or more name elements.43* A {@code Path} is considered to be an <i>empty path</i> if it consists44* solely of one name element that is empty. Accessing a file using an45* <i>empty path</i> is equivalent to accessing the default directory of the46* file system. {@code Path} defines the {@link #getFileName() getFileName},47* {@link #getParent getParent}, {@link #getRoot getRoot}, and {@link #subpath48* subpath} methods to access the path components or a subsequence of its name49* elements.50*51* <p> In addition to accessing the components of a path, a {@code Path} also52* defines the {@link #resolve(Path) resolve} and {@link #resolveSibling(Path)53* resolveSibling} methods to combine paths. The {@link #relativize relativize}54* method that can be used to construct a relative path between two paths.55* Paths can be {@link #compareTo compared}, and tested against each other using56* the {@link #startsWith startsWith} and {@link #endsWith endsWith} methods.57*58* <p> This interface extends {@link Watchable} interface so that a directory59* located by a path can be {@link #register registered} with a {@link60* WatchService} and entries in the directory watched. </p>61*62* <p> <b>WARNING:</b> This interface is only intended to be implemented by63* those developing custom file system implementations. Methods may be added to64* this interface in future releases. </p>65*66* <h2>Accessing Files</h2>67* <p> Paths may be used with the {@link Files} class to operate on files,68* directories, and other types of files. For example, suppose we want a {@link69* java.io.BufferedReader} to read text from a file "{@code access.log}". The70* file is located in a directory "{@code logs}" relative to the current working71* directory and is UTF-8 encoded.72* <pre>73* Path path = FileSystems.getDefault().getPath("logs", "access.log");74* BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);75* </pre>76*77* <a name="interop"></a><h2>Interoperability</h2>78* <p> Paths associated with the default {@link79* java.nio.file.spi.FileSystemProvider provider} are generally interoperable80* with the {@link java.io.File java.io.File} class. Paths created by other81* providers are unlikely to be interoperable with the abstract path names82* represented by {@code java.io.File}. The {@link java.io.File#toPath toPath}83* method may be used to obtain a {@code Path} from the abstract path name84* represented by a {@code java.io.File} object. The resulting {@code Path} can85* be used to operate on the same file as the {@code java.io.File} object. In86* addition, the {@link #toFile toFile} method is useful to construct a {@code87* File} from the {@code String} representation of a {@code Path}.88*89* <h2>Concurrency</h2>90* <p> Implementations of this interface are immutable and safe for use by91* multiple concurrent threads.92*93* @since 1.794* @see Paths95*/9697public interface Path98extends Comparable<Path>, Iterable<Path>, Watchable99{100/**101* Returns the file system that created this object.102*103* @return the file system that created this object104*/105FileSystem getFileSystem();106107/**108* Tells whether or not this path is absolute.109*110* <p> An absolute path is complete in that it doesn't need to be combined111* with other path information in order to locate a file.112*113* @return {@code true} if, and only if, this path is absolute114*/115boolean isAbsolute();116117/**118* Returns the root component of this path as a {@code Path} object,119* or {@code null} if this path does not have a root component.120*121* @return a path representing the root component of this path,122* or {@code null}123*/124Path getRoot();125126/**127* Returns the name of the file or directory denoted by this path as a128* {@code Path} object. The file name is the <em>farthest</em> element from129* the root in the directory hierarchy.130*131* @return a path representing the name of the file or directory, or132* {@code null} if this path has zero elements133*/134Path getFileName();135136/**137* Returns the <em>parent path</em>, or {@code null} if this path does not138* have a parent.139*140* <p> The parent of this path object consists of this path's root141* component, if any, and each element in the path except for the142* <em>farthest</em> from the root in the directory hierarchy. This method143* does not access the file system; the path or its parent may not exist.144* Furthermore, this method does not eliminate special names such as "."145* and ".." that may be used in some implementations. On UNIX for example,146* the parent of "{@code /a/b/c}" is "{@code /a/b}", and the parent of147* {@code "x/y/.}" is "{@code x/y}". This method may be used with the {@link148* #normalize normalize} method, to eliminate redundant names, for cases where149* <em>shell-like</em> navigation is required.150*151* <p> If this path has one or more elements, and no root component, then152* this method is equivalent to evaluating the expression:153* <blockquote><pre>154* subpath(0, getNameCount()-1);155* </pre></blockquote>156*157* @return a path representing the path's parent158*/159Path getParent();160161/**162* Returns the number of name elements in the path.163*164* @return the number of elements in the path, or {@code 0} if this path165* only represents a root component166*/167int getNameCount();168169/**170* Returns a name element of this path as a {@code Path} object.171*172* <p> The {@code index} parameter is the index of the name element to return.173* The element that is <em>closest</em> to the root in the directory hierarchy174* has index {@code 0}. The element that is <em>farthest</em> from the root175* has index {@link #getNameCount count}{@code -1}.176*177* @param index178* the index of the element179*180* @return the name element181*182* @throws IllegalArgumentException183* if {@code index} is negative, {@code index} is greater than or184* equal to the number of elements, or this path has zero name185* elements186*/187Path getName(int index);188189/**190* Returns a relative {@code Path} that is a subsequence of the name191* elements of this path.192*193* <p> The {@code beginIndex} and {@code endIndex} parameters specify the194* subsequence of name elements. The name that is <em>closest</em> to the root195* in the directory hierarchy has index {@code 0}. The name that is196* <em>farthest</em> from the root has index {@link #getNameCount197* count}{@code -1}. The returned {@code Path} object has the name elements198* that begin at {@code beginIndex} and extend to the element at index {@code199* endIndex-1}.200*201* @param beginIndex202* the index of the first element, inclusive203* @param endIndex204* the index of the last element, exclusive205*206* @return a new {@code Path} object that is a subsequence of the name207* elements in this {@code Path}208*209* @throws IllegalArgumentException210* if {@code beginIndex} is negative, or greater than or equal to211* the number of elements. If {@code endIndex} is less than or212* equal to {@code beginIndex}, or larger than the number of elements.213*/214Path subpath(int beginIndex, int endIndex);215216/**217* Tests if this path starts with the given path.218*219* <p> This path <em>starts</em> with the given path if this path's root220* component <em>starts</em> with the root component of the given path,221* and this path starts with the same name elements as the given path.222* If the given path has more name elements than this path then {@code false}223* is returned.224*225* <p> Whether or not the root component of this path starts with the root226* component of the given path is file system specific. If this path does227* not have a root component and the given path has a root component then228* this path does not start with the given path.229*230* <p> If the given path is associated with a different {@code FileSystem}231* to this path then {@code false} is returned.232*233* @param other234* the given path235*236* @return {@code true} if this path starts with the given path; otherwise237* {@code false}238*/239boolean startsWith(Path other);240241/**242* Tests if this path starts with a {@code Path}, constructed by converting243* the given path string, in exactly the manner specified by the {@link244* #startsWith(Path) startsWith(Path)} method. On UNIX for example, the path245* "{@code foo/bar}" starts with "{@code foo}" and "{@code foo/bar}". It246* does not start with "{@code f}" or "{@code fo}".247*248* @param other249* the given path string250*251* @return {@code true} if this path starts with the given path; otherwise252* {@code false}253*254* @throws InvalidPathException255* If the path string cannot be converted to a Path.256*/257boolean startsWith(String other);258259/**260* Tests if this path ends with the given path.261*262* <p> If the given path has <em>N</em> elements, and no root component,263* and this path has <em>N</em> or more elements, then this path ends with264* the given path if the last <em>N</em> elements of each path, starting at265* the element farthest from the root, are equal.266*267* <p> If the given path has a root component then this path ends with the268* given path if the root component of this path <em>ends with</em> the root269* component of the given path, and the corresponding elements of both paths270* are equal. Whether or not the root component of this path ends with the271* root component of the given path is file system specific. If this path272* does not have a root component and the given path has a root component273* then this path does not end with the given path.274*275* <p> If the given path is associated with a different {@code FileSystem}276* to this path then {@code false} is returned.277*278* @param other279* the given path280*281* @return {@code true} if this path ends with the given path; otherwise282* {@code false}283*/284boolean endsWith(Path other);285286/**287* Tests if this path ends with a {@code Path}, constructed by converting288* the given path string, in exactly the manner specified by the {@link289* #endsWith(Path) endsWith(Path)} method. On UNIX for example, the path290* "{@code foo/bar}" ends with "{@code foo/bar}" and "{@code bar}". It does291* not end with "{@code r}" or "{@code /bar}". Note that trailing separators292* are not taken into account, and so invoking this method on the {@code293* Path}"{@code foo/bar}" with the {@code String} "{@code bar/}" returns294* {@code true}.295*296* @param other297* the given path string298*299* @return {@code true} if this path ends with the given path; otherwise300* {@code false}301*302* @throws InvalidPathException303* If the path string cannot be converted to a Path.304*/305boolean endsWith(String other);306307/**308* Returns a path that is this path with redundant name elements eliminated.309*310* <p> The precise definition of this method is implementation dependent but311* in general it derives from this path, a path that does not contain312* <em>redundant</em> name elements. In many file systems, the "{@code .}"313* and "{@code ..}" are special names used to indicate the current directory314* and parent directory. In such file systems all occurrences of "{@code .}"315* are considered redundant. If a "{@code ..}" is preceded by a316* non-"{@code ..}" name then both names are considered redundant (the317* process to identify such names is repeated until it is no longer318* applicable).319*320* <p> This method does not access the file system; the path may not locate321* a file that exists. Eliminating "{@code ..}" and a preceding name from a322* path may result in the path that locates a different file than the original323* path. This can arise when the preceding name is a symbolic link.324*325* @return the resulting path or this path if it does not contain326* redundant name elements; an empty path is returned if this path327* does have a root component and all name elements are redundant328*329* @see #getParent330* @see #toRealPath331*/332Path normalize();333334// -- resolution and relativization --335336/**337* Resolve the given path against this path.338*339* <p> If the {@code other} parameter is an {@link #isAbsolute() absolute}340* path then this method trivially returns {@code other}. If {@code other}341* is an <i>empty path</i> then this method trivially returns this path.342* Otherwise this method considers this path to be a directory and resolves343* the given path against this path. In the simplest case, the given path344* does not have a {@link #getRoot root} component, in which case this method345* <em>joins</em> the given path to this path and returns a resulting path346* that {@link #endsWith ends} with the given path. Where the given path has347* a root component then resolution is highly implementation dependent and348* therefore unspecified.349*350* @param other351* the path to resolve against this path352*353* @return the resulting path354*355* @see #relativize356*/357Path resolve(Path other);358359/**360* Converts a given path string to a {@code Path} and resolves it against361* this {@code Path} in exactly the manner specified by the {@link362* #resolve(Path) resolve} method. For example, suppose that the name363* separator is "{@code /}" and a path represents "{@code foo/bar}", then364* invoking this method with the path string "{@code gus}" will result in365* the {@code Path} "{@code foo/bar/gus}".366*367* @param other368* the path string to resolve against this path369*370* @return the resulting path371*372* @throws InvalidPathException373* if the path string cannot be converted to a Path.374*375* @see FileSystem#getPath376*/377Path resolve(String other);378379/**380* Resolves the given path against this path's {@link #getParent parent}381* path. This is useful where a file name needs to be <i>replaced</i> with382* another file name. For example, suppose that the name separator is383* "{@code /}" and a path represents "{@code dir1/dir2/foo}", then invoking384* this method with the {@code Path} "{@code bar}" will result in the {@code385* Path} "{@code dir1/dir2/bar}". If this path does not have a parent path,386* or {@code other} is {@link #isAbsolute() absolute}, then this method387* returns {@code other}. If {@code other} is an empty path then this method388* returns this path's parent, or where this path doesn't have a parent, the389* empty path.390*391* @param other392* the path to resolve against this path's parent393*394* @return the resulting path395*396* @see #resolve(Path)397*/398Path resolveSibling(Path other);399400/**401* Converts a given path string to a {@code Path} and resolves it against402* this path's {@link #getParent parent} path in exactly the manner403* specified by the {@link #resolveSibling(Path) resolveSibling} method.404*405* @param other406* the path string to resolve against this path's parent407*408* @return the resulting path409*410* @throws InvalidPathException411* if the path string cannot be converted to a Path.412*413* @see FileSystem#getPath414*/415Path resolveSibling(String other);416417/**418* Constructs a relative path between this path and a given path.419*420* <p> Relativization is the inverse of {@link #resolve(Path) resolution}.421* This method attempts to construct a {@link #isAbsolute relative} path422* that when {@link #resolve(Path) resolved} against this path, yields a423* path that locates the same file as the given path. For example, on UNIX,424* if this path is {@code "/a/b"} and the given path is {@code "/a/b/c/d"}425* then the resulting relative path would be {@code "c/d"}. Where this426* path and the given path do not have a {@link #getRoot root} component,427* then a relative path can be constructed. A relative path cannot be428* constructed if only one of the paths have a root component. Where both429* paths have a root component then it is implementation dependent if a430* relative path can be constructed. If this path and the given path are431* {@link #equals equal} then an <i>empty path</i> is returned.432*433* <p> For any two {@link #normalize normalized} paths <i>p</i> and434* <i>q</i>, where <i>q</i> does not have a root component,435* <blockquote>436* <i>p</i><tt>.relativize(</tt><i>p</i><tt>.resolve(</tt><i>q</i><tt>)).equals(</tt><i>q</i><tt>)</tt>437* </blockquote>438*439* <p> When symbolic links are supported, then whether the resulting path,440* when resolved against this path, yields a path that can be used to locate441* the {@link Files#isSameFile same} file as {@code other} is implementation442* dependent. For example, if this path is {@code "/a/b"} and the given443* path is {@code "/a/x"} then the resulting relative path may be {@code444* "../x"}. If {@code "b"} is a symbolic link then is implementation445* dependent if {@code "a/b/../x"} would locate the same file as {@code "/a/x"}.446*447* @param other448* the path to relativize against this path449*450* @return the resulting relative path, or an empty path if both paths are451* equal452*453* @throws IllegalArgumentException454* if {@code other} is not a {@code Path} that can be relativized455* against this path456*/457Path relativize(Path other);458459/**460* Returns a URI to represent this path.461*462* <p> This method constructs an absolute {@link URI} with a {@link463* URI#getScheme() scheme} equal to the URI scheme that identifies the464* provider. The exact form of the scheme specific part is highly provider465* dependent.466*467* <p> In the case of the default provider, the URI is hierarchical with468* a {@link URI#getPath() path} component that is absolute. The query and469* fragment components are undefined. Whether the authority component is470* defined or not is implementation dependent. There is no guarantee that471* the {@code URI} may be used to construct a {@link java.io.File java.io.File}.472* In particular, if this path represents a Universal Naming Convention (UNC)473* path, then the UNC server name may be encoded in the authority component474* of the resulting URI. In the case of the default provider, and the file475* exists, and it can be determined that the file is a directory, then the476* resulting {@code URI} will end with a slash.477*478* <p> The default provider provides a similar <em>round-trip</em> guarantee479* to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it480* is guaranteed that481* <blockquote><tt>482* {@link Paths#get(URI) Paths.get}(</tt><i>p</i><tt>.toUri()).equals(</tt><i>p</i>483* <tt>.{@link #toAbsolutePath() toAbsolutePath}())</tt>484* </blockquote>485* so long as the original {@code Path}, the {@code URI}, and the new {@code486* Path} are all created in (possibly different invocations of) the same487* Java virtual machine. Whether other providers make any guarantees is488* provider specific and therefore unspecified.489*490* <p> When a file system is constructed to access the contents of a file491* as a file system then it is highly implementation specific if the returned492* URI represents the given path in the file system or it represents a493* <em>compound</em> URI that encodes the URI of the enclosing file system.494* A format for compound URIs is not defined in this release; such a scheme495* may be added in a future release.496*497* @return the URI representing this path498*499* @throws java.io.IOError500* if an I/O error occurs obtaining the absolute path, or where a501* file system is constructed to access the contents of a file as502* a file system, and the URI of the enclosing file system cannot be503* obtained504*505* @throws SecurityException506* In the case of the default provider, and a security manager507* is installed, the {@link #toAbsolutePath toAbsolutePath} method508* throws a security exception.509*/510URI toUri();511512/**513* Returns a {@code Path} object representing the absolute path of this514* path.515*516* <p> If this path is already {@link Path#isAbsolute absolute} then this517* method simply returns this path. Otherwise, this method resolves the path518* in an implementation dependent manner, typically by resolving the path519* against a file system default directory. Depending on the implementation,520* this method may throw an I/O error if the file system is not accessible.521*522* @return a {@code Path} object representing the absolute path523*524* @throws java.io.IOError525* if an I/O error occurs526* @throws SecurityException527* In the case of the default provider, a security manager528* is installed, and this path is not absolute, then the security529* manager's {@link SecurityManager#checkPropertyAccess(String)530* checkPropertyAccess} method is invoked to check access to the531* system property {@code user.dir}532*/533Path toAbsolutePath();534535/**536* Returns the <em>real</em> path of an existing file.537*538* <p> The precise definition of this method is implementation dependent but539* in general it derives from this path, an {@link #isAbsolute absolute}540* path that locates the {@link Files#isSameFile same} file as this path, but541* with name elements that represent the actual name of the directories542* and the file. For example, where filename comparisons on a file system543* are case insensitive then the name elements represent the names in their544* actual case. Additionally, the resulting path has redundant name545* elements removed.546*547* <p> If this path is relative then its absolute path is first obtained,548* as if by invoking the {@link #toAbsolutePath toAbsolutePath} method.549*550* <p> The {@code options} array may be used to indicate how symbolic links551* are handled. By default, symbolic links are resolved to their final552* target. If the option {@link LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} is553* present then this method does not resolve symbolic links.554*555* Some implementations allow special names such as "{@code ..}" to refer to556* the parent directory. When deriving the <em>real path</em>, and a557* "{@code ..}" (or equivalent) is preceded by a non-"{@code ..}" name then558* an implementation will typically cause both names to be removed. When559* not resolving symbolic links and the preceding name is a symbolic link560* then the names are only removed if it guaranteed that the resulting path561* will locate the same file as this path.562*563* @param options564* options indicating how symbolic links are handled565*566* @return an absolute path represent the <em>real</em> path of the file567* located by this object568*569* @throws IOException570* if the file does not exist or an I/O error occurs571* @throws SecurityException572* In the case of the default provider, and a security manager573* is installed, its {@link SecurityManager#checkRead(String) checkRead}574* method is invoked to check read access to the file, and where575* this path is not absolute, its {@link SecurityManager#checkPropertyAccess(String)576* checkPropertyAccess} method is invoked to check access to the577* system property {@code user.dir}578*/579Path toRealPath(LinkOption... options) throws IOException;580581/**582* Returns a {@link File} object representing this path. Where this {@code583* Path} is associated with the default provider, then this method is584* equivalent to returning a {@code File} object constructed with the585* {@code String} representation of this path.586*587* <p> If this path was created by invoking the {@code File} {@link588* File#toPath toPath} method then there is no guarantee that the {@code589* File} object returned by this method is {@link #equals equal} to the590* original {@code File}.591*592* @return a {@code File} object representing this path593*594* @throws UnsupportedOperationException595* if this {@code Path} is not associated with the default provider596*/597File toFile();598599// -- watchable --600601/**602* Registers the file located by this path with a watch service.603*604* <p> In this release, this path locates a directory that exists. The605* directory is registered with the watch service so that entries in the606* directory can be watched. The {@code events} parameter is the events to607* register and may contain the following events:608* <ul>609* <li>{@link StandardWatchEventKinds#ENTRY_CREATE ENTRY_CREATE} -610* entry created or moved into the directory</li>611* <li>{@link StandardWatchEventKinds#ENTRY_DELETE ENTRY_DELETE} -612* entry deleted or moved out of the directory</li>613* <li>{@link StandardWatchEventKinds#ENTRY_MODIFY ENTRY_MODIFY} -614* entry in directory was modified</li>615* </ul>616*617* <p> The {@link WatchEvent#context context} for these events is the618* relative path between the directory located by this path, and the path619* that locates the directory entry that is created, deleted, or modified.620*621* <p> The set of events may include additional implementation specific622* event that are not defined by the enum {@link StandardWatchEventKinds}623*624* <p> The {@code modifiers} parameter specifies <em>modifiers</em> that625* qualify how the directory is registered. This release does not define any626* <em>standard</em> modifiers. It may contain implementation specific627* modifiers.628*629* <p> Where a file is registered with a watch service by means of a symbolic630* link then it is implementation specific if the watch continues to depend631* on the existence of the symbolic link after it is registered.632*633* @param watcher634* the watch service to which this object is to be registered635* @param events636* the events for which this object should be registered637* @param modifiers638* the modifiers, if any, that modify how the object is registered639*640* @return a key representing the registration of this object with the641* given watch service642*643* @throws UnsupportedOperationException644* if unsupported events or modifiers are specified645* @throws IllegalArgumentException646* if an invalid combination of events or modifiers is specified647* @throws ClosedWatchServiceException648* if the watch service is closed649* @throws NotDirectoryException650* if the file is registered to watch the entries in a directory651* and the file is not a directory <i>(optional specific exception)</i>652* @throws IOException653* if an I/O error occurs654* @throws SecurityException655* In the case of the default provider, and a security manager is656* installed, the {@link SecurityManager#checkRead(String) checkRead}657* method is invoked to check read access to the file.658*/659@Override660WatchKey register(WatchService watcher,661WatchEvent.Kind<?>[] events,662WatchEvent.Modifier... modifiers)663throws IOException;664665/**666* Registers the file located by this path with a watch service.667*668* <p> An invocation of this method behaves in exactly the same way as the669* invocation670* <pre>671* watchable.{@link #register(WatchService,WatchEvent.Kind[],WatchEvent.Modifier[]) register}(watcher, events, new WatchEvent.Modifier[0]);672* </pre>673*674* <p> <b>Usage Example:</b>675* Suppose we wish to register a directory for entry create, delete, and modify676* events:677* <pre>678* Path dir = ...679* WatchService watcher = ...680*681* WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);682* </pre>683* @param watcher684* The watch service to which this object is to be registered685* @param events686* The events for which this object should be registered687*688* @return A key representing the registration of this object with the689* given watch service690*691* @throws UnsupportedOperationException692* If unsupported events are specified693* @throws IllegalArgumentException694* If an invalid combination of events is specified695* @throws ClosedWatchServiceException696* If the watch service is closed697* @throws NotDirectoryException698* If the file is registered to watch the entries in a directory699* and the file is not a directory <i>(optional specific exception)</i>700* @throws IOException701* If an I/O error occurs702* @throws SecurityException703* In the case of the default provider, and a security manager is704* installed, the {@link SecurityManager#checkRead(String) checkRead}705* method is invoked to check read access to the file.706*/707@Override708WatchKey register(WatchService watcher,709WatchEvent.Kind<?>... events)710throws IOException;711712// -- Iterable --713714/**715* Returns an iterator over the name elements of this path.716*717* <p> The first element returned by the iterator represents the name718* element that is closest to the root in the directory hierarchy, the719* second element is the next closest, and so on. The last element returned720* is the name of the file or directory denoted by this path. The {@link721* #getRoot root} component, if present, is not returned by the iterator.722*723* @return an iterator over the name elements of this path.724*/725@Override726Iterator<Path> iterator();727728// -- compareTo/equals/hashCode --729730/**731* Compares two abstract paths lexicographically. The ordering defined by732* this method is provider specific, and in the case of the default733* provider, platform specific. This method does not access the file system734* and neither file is required to exist.735*736* <p> This method may not be used to compare paths that are associated737* with different file system providers.738*739* @param other the path compared to this path.740*741* @return zero if the argument is {@link #equals equal} to this path, a742* value less than zero if this path is lexicographically less than743* the argument, or a value greater than zero if this path is744* lexicographically greater than the argument745*746* @throws ClassCastException747* if the paths are associated with different providers748*/749@Override750int compareTo(Path other);751752/**753* Tests this path for equality with the given object.754*755* <p> If the given object is not a Path, or is a Path associated with a756* different {@code FileSystem}, then this method returns {@code false}.757*758* <p> Whether or not two path are equal depends on the file system759* implementation. In some cases the paths are compared without regard760* to case, and others are case sensitive. This method does not access the761* file system and the file is not required to exist. Where required, the762* {@link Files#isSameFile isSameFile} method may be used to check if two763* paths locate the same file.764*765* <p> This method satisfies the general contract of the {@link766* java.lang.Object#equals(Object) Object.equals} method. </p>767*768* @param other769* the object to which this object is to be compared770*771* @return {@code true} if, and only if, the given object is a {@code Path}772* that is identical to this {@code Path}773*/774boolean equals(Object other);775776/**777* Computes a hash code for this path.778*779* <p> The hash code is based upon the components of the path, and780* satisfies the general contract of the {@link Object#hashCode781* Object.hashCode} method.782*783* @return the hash-code value for this path784*/785int hashCode();786787/**788* Returns the string representation of this path.789*790* <p> If this path was created by converting a path string using the791* {@link FileSystem#getPath getPath} method then the path string returned792* by this method may differ from the original String used to create the path.793*794* <p> The returned path string uses the default name {@link795* FileSystem#getSeparator separator} to separate names in the path.796*797* @return the string representation of this path798*/799String toString();800}801802803