Java.nio.file.Path

Source: Internet
Author: User

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 Separ Ated by a special separator or delimiter.
2. ARoot Component, that is identifies a file system hierarchy, may also is Present.
3. The name element isFarthestFrom the root of the directory hierarchy is the name of a file or directory. The other name elements is directory Names.
4. APathCan represent a root, a root and a sequence of names, or simply one or more name Elements.
5. APathis consideredEmpty PathIf it consists solely of one name element is Empty.
6. Accessing a file using anEmpty Pathis equivalent to accessing the default directory of the file System.

Method Classify:
1.PathDefines thegetFileName,getParent,getRoot, andsubpathMethods to access the path, components, or a subsequence of its name Elements.
2. In addition to accessing the components of a path, aPathalso defines theresolveandresolveSiblingMethods to combine Paths.
3. TherelativizeMethod that can is used to construct a relative path between the Paths. Paths cancompared,
and tested against each of the other using thestartsWithandendWithMethods.
4. This interface extendsWatchableInterface so, directory located by a path can isregisteredWith aWatchServiceand entries in the directory Watched.

accessing Files:
1. Paths may used with theFilesclass to operate on files, directories, and other types of files.
For example, Suppose we want aBufferedReaderTo read the 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 is used to obtain a from the Path abstract path name represented by a java.io.File object.
  The resulting Path can used to operate on the same file as the java.io.File Object.
2. In addition, the toFile method was useful to construct a from the File representation of String a Path .
Concurrency
Implementations of this interface is immutable and safe for use by multiple concurrent THREADS.

Method
Method signature Significance
int compareTo(Path other) Compare two paths sequentially
Boolean endsWith(Path other) Tests whether a path object ends with the given path
Boolean endsWith(String other) Tests whether a path object ends with the given string, and the string is converted to the Path object
Boolean equals(Object other)
Path GetFileName()
FileSystem Getfilesystem() Returns the file system object that created the Path object
Path getName(int Index) Returns a name consisting of a path object in the Paths object
int GetNameCount() Returns the number of name elements in the Path.
Path getParent() Returns the parent path, or null If this path does not has a parent.
Path getroot() Returns The root component of this path as a Path object, or null If this path does not has a root component.
Boolean isabsolute() Tells whether or not the this path is Absolute.
iterator<path> Iterator() Returns an iterator over the name elements of this path.
Path Normalize() Remove such AS. And: the path element such as Redundancy.

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) Returns the relative path to parse with this, relative to Other.
Path Resolve(path other) If other is an absolute path, the other is returned, otherwise, the path obtained by connecting this and other is Returned.
Path Resolve(String other) If other is an absolute path, the other is returned, otherwise, the path obtained by connecting this and other is Returned.
Path resolvesibling(path other) If other is an absolute path, the other is returned, otherwise, the path is obtained by connecting the parent path of this and other.
Path resolvesibling(String other) If other is an absolute path, the other is returned, otherwise, the path is obtained by connecting the parent path of this and other.
Boolean startsWith(Path other) Similar EndsWith
Boolean startsWith(String other) Similar EndsWith
Path subpath(int beginindex, int EndIndex) Returns a relative That's Path 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.