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编程. ...
随机推荐
- ebox学习之SD & fat 配置
fatfs可配置项很多,相关的配置均在ffconfig.h文件中 /*----------------------------------------------------------------- ...
- MySQL主从同步配置(Ubuntu)
一.在两台Linux机器上安装MySQL 二.Master主服务器配置(192.168.1.3) 1.编辑my.cnf(命令查找文件位置:find / -name my.cnf) vi /etc/my ...
- windows下自动FTP的脚本
之前发过一篇如何自动FTP的文章,不过当时的脚本都是在Unix下测试通过的.而如果在windows下实现自动FTP的功能,则需要通过如下方式: 1. 建立ftp123.bat文件 open I ...
- 进制转换及API接口中的转换
//十进制转二进制Console.WriteLine("十进制166的二进制表示: "+Convert.ToString(166, 2));//十进制转八进制Console.Wri ...
- SQL 语句格式
SELECT `menuid`, SUM(`num`)AS total, `storeid`, DATE_FORMAT(`dateline`,'%Y-%m-%d') days FROM loss WH ...
- 机器人操作臂运动学入门一--D-H参数标定
最近重新学习机器人方面的知识,想到一年以前在学校选修<机器人学技术基础>这门课的时候,老师虽然讲机器人的各个方面的知识都讲到了,但只是浮光绿影的的提到,并没有真正讲到深处,我的理解也没有更 ...
- 【转】关于字符编码,你所需要知道的(ASCII,Unicode,Utf-8,GB2312…)
转载地址:http://www.imkevinyang.com/2010/06/%E5%85%B3%E4%BA%8E%E5%AD%97%E7%AC%A6%E7%BC%96%E7%A0%81%EF%BC ...
- mysql优化一 之 优化内容概述及开启慢查日志的相关配置
1-1数据库优化的目的 首先是为了避免出现页面访问错误(基本有三种) (1)由于数据库连接timeout产生的页面5XX错误 (2)由于慢查询造成页面无法加载 (3)由于阻塞造成的数据无法提交 其次: ...
- scoi2010&&bzoj1858序列操作
[题目描述] lxhgww最近收到了一个01序列,序列里面包含了n个数,这些数要么是0,要么是1,现在对于这个序列有五种变换操作和询问操作: 0 a b 把[a, b]区间内的所有数全变成0 1 a ...
- Web App适配不同屏幕的几点建议
安卓设备在屏幕尺寸和像素密度上差别很大,因此在使用WebView加载网页时就需要考虑到这种差别,对我们的网页做出精心的设计以在不同的屏幕上都能得到合适的展现.通常情况下,我们需要考虑到两个因素:1.视 ...