java.nio.file.Path
public interface Path
extends Comparable<Path>, Iterable<Path>, Watchable
1. APathrepresents 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. APathcan represent a root, a root and a sequence of names, or simply one or more name elements.
5. APathis 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.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 be used to construct a relative path between two paths. Paths can becompared,
and tested against each other using thestartsWithandendWithmethods.
4. This interface extendsWatchableinterface so that a directory located by a path can beregisteredwith aWatchServiceand entries in the directory watched. accessing files:
1. Paths may be used with theFilesclass to operate on files, directories, and other types of files.
For example, suppose we want aBufferedReaderto 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.
Path path = FileSystems.getDefault().getPath("logs", "access.log");
BufferReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);
Interoperability:
1. ThetoPathmethod may be used to obtain aPathfrom the abstract path name represented by ajava.io.Fileobject.
The resultingPathcan be used to operate on the same file as thejava.io.Fileobject.
2. In addition, thetoFilemethod is useful to construct aFilefrom theStringrepresentation of aPath.
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() | 移除诸如. 和.. 等冗余的路径元素。 |
|
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的更多相关文章
- Java JsonPath grab InvalidPathException in code, you must be catching Java 7's java.nio.file.InvalidPathException instead of JsonPath's com.jayway.jsonpath.InvalidPathExceptio
I am using JsonPath and am able to parse my data and get the values when the path provided is correc ...
- Java7 新特性 —— java.nio.file 文件操作
本文部分摘自 On Java 8 自 Java7 开始,Java 终于简化了文件读写的基本操作,新增了 java.nio.file 库,通过与 Java8 新增的 stream 结合可以使得文件操作变 ...
- Docker启动Elasticsearch报错java.nio.file.AccessDeniedException
报错信息 Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes 问题分析 表面上是说容 ...
- java.nio.file.FileSystemException: D:\kafka_2.12-2.1.0\kafka_2.12-2.1.0\logs\__consumer_offsets-30\00000000000000000000.timeindex.cleaned: 另一个程序正在使用此文件,进程无法访问。
在启动kafka时候报错: java.nio.file.FileSystemException: D:\kafka_2.12-2.1.0\kafka_2.12-2.1.0\logs\__consume ...
- 使用java类加载器,报异常java.nio.file.InvalidPathException
String path = Label.class.getClassLoader().getResource("").getPath(); /F:/idea-Java/ImageD ...
- java.nio.file.NoSuchFileException
springboot +es es 2.1.0 参考这个 https://www.cnblogs.com/yueshutong/p/9381543.html cluster-nodes :改成127. ...
- kafka - java.nio.file.FileSystemException
在启动Kafka时报错无法启动 E:\kafka_2.12-2.3.1\kafka-logs\__consumer_offsets-48\00000000000000000000.timeindex. ...
- 2.2.5 NIO.2 Path 和 Java 已有的 File 类
NIO与IO交互 toPath() File -- Path toFile() Path -- File Demo: import java.io.File; import java.nio.file ...
- JAVA基础知识之NIO.2——Path,Paths,Files
NIO.2 JDK7对NIO进行了重大改进,主要包含以下两方面 新增Path接口,Paths工具类,Files工具类. 这些接口和工具类对NIO中的功能进行了高度封装,大大简化了文件系统的IO编程. ...
随机推荐
- 安装Oracle问题总结
Oracle安装很多次,这次是最郁闷. 第一次安装失败,考虑可能是软件问题(以往学生给的软件),重新从官网下载 快下载完时,360清理电脑垃圾空间,手残,关闭浏览器,又开始重新下载 下载的同时,我开始 ...
- EntityFramework Core技术线路(EF7已经更名为EF Core,并于2016年6月底发布)
官方文档英文地址:https://github.com/aspnet/EntityFramework/wiki/Roadmap 历经延期和更名,新版本的实体框架终于要和大家见面了,虽然还有点害羞.请大 ...
- winApi
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- 记一次 IDEA mybatis.generator 自定义扩展插件
在使用 idea mybatis.generator 生成的代码,遇到 生成的代码很多重复的地方, 虽然代码是生成的,我们也不应该允许重复的代码出现,因为这些代码后期都要来手动维护. 对于生成时间戳注 ...
- linux定时任务的设置
1. 键入 crontab -e 编辑crontab服务文件 例如 文件内容如下: */2 * * * * /bin/sh /home/admin/jiaoben/buy/deleteFile.s ...
- linux shell脚本使用结构化命令(2)
一.for命令 二.while命令 三.until命令 1.for命令基本格式 for var in list do commands done oracle@suse:~/testshell> ...
- MyBatis foreach标签遍历数组
有时候开发中需要根据多个ID去查询,可以将ID封装为List或者数组然后使用MyBatis中的foreach标签构建in条件. 这里我将ID封装为String[]作为参数. <select id ...
- 放在NSArray、NSDictionary等容器内的对象Item,Item中的property在程序运行过程中被无故释放
可能是被释放的property本身是OC对象而它的属性被误写成assign,例如: @interface MyItem : Object @property (nonatomic, assign) N ...
- Dynamics AX 2012 R2 SSRS报表在VS2010中预览没有数据
今天,Reinhard 在VS中制作SSRS报表,预览的时候发现显示不出数据. 仔细检查了数据处理环节和临时表里的数据,都发现没有问题. 用同事的账号登陆同样的开发环境,发现他的账号可以在VS中预览到 ...
- amgular $q用法
amgular $q用法 在用JQuery的时候就知道 promise 是 Js异步编程模式的一种模式,但是不是很明白他跟JQuery的deferred对象有什么区别.随着公司项目的进行,要跟后台 ...