標籤:pre height 字元 str between work 路徑 uri whether
public interface Pathextends Comparable<Path>, Iterable<Path>, Watchable
1. A Path represents a path that is hierarchical and composed of a sequence of directory and file name elements separated by a special separator or delimiter.
2. A root component, that identifies a file system hierarchy, may also be present.
3. The name element that is farthest from the root of the directory hierarchy is the name of a file or directory. The other name elements are directory names.
4. A Path can represent a root, a root and a sequence of names, or simply one or more name elements.
5. A Path is considered to be an empty path if it consists solely of one name element that is empty.
6. Accessing a file using an empty path is equivalent to accessing the default directory of the file system.
method classify:
1. Path defines the getFileName, getParent, getRoot, and subpath methods to access the path components or a subsequence of its name elements.
2. In addition to accessing the components of a path, a Path also defines the resolve and resolveSibling methods to combine paths.
3. The relativize method that can be used to construct a relative path between two paths. Paths can be compared,
and tested against each other using the startsWith and endWith methods.
4. This interface extends Watchable interface so that a directory located by a path can be registered with a WatchService and entries in the directory watched.
accessing files:
1. Paths may be used with the Files class to operate on files, directories, and other types of files.
For example, suppose we want a BufferedReader to read text from a file "access.log".
The file is located in a directory "logs" relative to the current working directory and is UTF-8 encoded.
1 Path path = FileSystems.getDefault().getPath("logs", "access.log");2 BufferReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);
Interoperability:
1. The toPath method may be used to obtain a Path from the abstract path name represented by a java.io.File object.
The resulting Path can be used to operate on the same file as the java.io.File object.
2. In addition, the toFile method is useful to construct a File from the String representation of a Path.
concurrency:
Implementations of this interface are immutable and safe for use by multiple concurrent threads.
method:
| 方法簽名 |
意義 |
| int compareTo(Path other) |
按順序比較兩個路徑 |
| boolean endsWith(Path other) |
測試一個Path對象是否以給定的path為結尾 |
| boolean endsWith(String other) |
測試一個Path對象是否以給定的字串為結尾,字串會轉換為Path對象 |
| boolean equals(Object other) |
|
| Path getFileName() |
|
| FileSystem getFileSystem() |
返回建立Path對象的檔案系統對象 |
| Path getName(int index) |
以Path對象返迴路徑對象中一個名字組成 |
| int getNameCount() |
Returns the number of name elements in the path. |
| Path getParent() |
Returns the parent path, or null if this path does not have a parent. |
| Path getRoot() |
Returns the root component of this path as a Path object, or null if this path does not have a root component. |
| boolean isAbsolute() |
Tells whether or not this path is absolute. |
| Iterator<Path> iterator() |
Returns an iterator over the name elements of this path. |
| Path normalize() |
移除諸如. 和.. 等冗餘的路徑元素。 |
WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) |
Registers the file located by this path with a watch service. |
| WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) |
Registers the file located by this path with a watch service. |
| Path relativize(Path other) |
返回用this 進行解析,相對於other 的相對路徑。 |
| Path resolve(Path other) |
如果other 是絕對路徑,那麼就返回other ;否則,返回通過串連this 和other 獲得的路徑。 |
| Path resolve(String other) |
如果other 是絕對路徑,那麼就返回other ;否則,返回通過串連this 和other 獲得的路徑。 |
| Path resolveSibling(Path other) |
如果other 是絕對路徑,那麼就返回other ;否則,返回通過串連this 的父路徑和other 獲得的路徑。 |
| Path resolveSibling(String other) |
如果other 是絕對路徑,那麼就返回other ;否則,返回通過串連this 的父路徑和other 獲得的路徑。 |
| boolean startsWith(Path other) |
類似endsWith |
| boolean startsWith(String other) |
類似endsWith |
| Path subpath(int beginIndex, int endIndex) |
Returns a relative Path that is a subsequence of the name elements of this path. |
| Path toAbsolutePath() |
Returns a Path object representing the absolute path of this path. |
| File toFile() |
Returns a File object representing this path. |
| Path toRealPath(LinkOption... options) |
Returns the real path of an existing file. |
| URI toUri() |
Returns a URI to represent this path. |
java.nio.file.Path