java.nio.file.Path
public interface Path
extends Comparable<Path>, Iterable<Path>, Watchable
1. APath
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. APath
can represent a root, a root and a sequence of names, or simply one or more name elements.
5. APath
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 thegetFileName
,getParent
,getRoot
, andsubpath
methods to access the path components or a subsequence of its name elements.
2. In addition to accessing the components of a path, aPath
also defines theresolve
andresolveSibling
methods to combine paths.
3. Therelativize
method that can be used to construct a relative path between two paths. Paths can becompared
,
and tested against each other using thestartsWith
andendWith
methods.
4. This interface extendsWatchable
interface so that a directory located by a path can beregistered
with aWatchService
and entries in the directory watched. accessing files:
1. Paths may be used with theFiles
class to operate on files, directories, and other types of files.
For example, suppose we want aBufferedReader
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.
Path path = FileSystems.getDefault().getPath("logs", "access.log");
BufferReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);
Interoperability:
1. ThetoPath
method may be used to obtain aPath
from the abstract path name represented by ajava.io.File
object.
The resultingPath
can be used to operate on the same file as thejava.io.File
object.
2. In addition, thetoFile
method is useful to construct aFile
from theString
representation 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编程. ...
随机推荐
- paper 130:MatLab分类器大全(svm,knn,随机森林等)
train_data是训练特征数据, train_label是分类标签.Predict_label是预测的标签.MatLab训练数据, 得到语义标签向量 Scores(概率输出).1.逻辑回归(多项式 ...
- webapi返回json格式优化
一.设置webapi返回json格式 在App_Start下的WebApiConfig的注册函数Register中添加下面这代码 config.Formatters.Remove(config.For ...
- css深入理解z-index
z-index取值 z-index:auto;z-index:<integer>;z-index:inherit;继承 特性: 1.支持负值2.支持css3 animation动画;3.在 ...
- 移动设备如何打开RMS加密的文档
关键字:RMS. AZure RMS.IPhone.Android.Office365.Sharepoint.Exchange 最近总是碰到要求用苹果手机及安卓手机阅读RMS加密文档的需求,经过查找相 ...
- MySQL命令大全:MySQL常用命令手册、MySQL命令行大全、查询工具
1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...
- Spring学习笔记1——基础知识 (转)
1.在java开发领域,Spring相对于EJB来说是一种轻量级的,非侵入性的Java开发框架,曾经有两本很畅销的书<Expert one-on-one J2EE Design and Deve ...
- UICollectionView 自定义组头组尾的XIB方法
UICollectionView的加载方式和Tableview很像,基本上加载的方法都差不多,尤其是它的数据源的方法和代理方法基本上类似,只不过是名字上有点细微的差别而已.这里面不赘述. 1. UIC ...
- jquery 提交From表单
/** * 异步提交From */ function ajaxSubmitFrom (btnId,fromId,url){ $(btnId).click(function () { var optio ...
- (Interface)接口特点
接口是一种规范.只要一个类继承了一个接口,这个类就必须实现这个接口中所有的成员 为了多态. 接口不能被实例化.也就是说,接口不能new(不能创建对象) 接口中的成员不能加"访问修饰符&quo ...
- UITableViewCell内放置复杂结构的subview,但subview中的Button不响应点击事件
原因可能是subview的frame没设置或者不对,这种情况下subview的内容依然正常显示,但是无法接收点击响应的消息. 具体来说就是缺少了下面这句代码: // subview - (id)ini ...