Java:Path与Paths
0、说明
用于读Path操作的接口(Path)与实现类(Paths)
1、模块:java.nio.file.Path、java.nio.file.Paths
2、方法
2.1、Paths
只有两个静态方法,用法:Paths.xxx( ... )
| Path | get( String first , String... more ) |
用连接符把这些参数中的String连接起来,得到一个对应的Path(和Path.of( ... )相同) Windows中的连接符是\ |
| Path | get( URI uri ) | 将一个给定的URI转化为Path对象 |
2.2、Path
2.2.1、静态方法,用法:Path.xxx( ... )
| Path | of( String first , String... more) |
与Paths.get(...)作用相同 返回一个Path对象 |
| Path | of( URI uri ) |
2.2.2、实例方法,用法:p.xxx( ... )
返回值类型 |
方法 |
说明 |
| int | compareTo(Path other) | 比较两个Path |
| boolean | endsWith(String other) | 判断该Path是否以other结尾 |
| boolean | endsWith(Path other) | 判断该Path是否以另一个Path结尾 |
| boolean | equals(Object other) | 判断该Path是否和另一个元素相等 |
| Path | getFileName() | 文件名对应的Path |
| FileSystem | getFileSystem() | 返回构造了这个Path的文件系统 |
| Path | getName(int index) |
返回Path某一级目录的名字 比如 usr\Docs\Test,对应0/1/2分别是usr、Docs、Test |
| int | getNameCount() | 返回Path目录有几级,常配合getName(int index)使用 |
| Path | getParent() | 获取父目录的Path |
| Path | getRoot() | 获取根目录的Path |
| int | hashCode() | hash code |
| boolean | isAbsolute() | 判断该Path是否是绝对路径 |
| Iterator<Path> | iterator() | 实现迭代器,允许对Path[ ]使用for each遍历 |
| Path | normalize() | 将路径正规化(即转换为不含.和..的绝对路径) |
| WatchKey | register(WatchService watcher, WatchEvent.Kind<?>... events) | |
| WatchKey | register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) | |
| Path | relativize(Path other) | 返回两个路径间的相对路径 |
| Path | resolve(String other) |
如果other是绝对路径,返回other; 如果other是null,返回this; 否则,在this之后拼接other形成新Path |
| Path | resolve(Path other) | |
| Path | resolveSibling(String other) |
如果other是绝对路径,返回other; 如果other是null,返回this; 否则,在this的父目录下拼接other形成新的Path |
| Path | resolveSibling(Path other) | |
| boolean | startsWith(String other) | 判断该Path是否以other开头 |
| boolean | startsWith(Path other) | 判断该Path是否以other开头 |
| Path | subPath(int start , int end) | 返回从start到end的subpath |
| Path | toAbsolutePath() | 返回绝对路径 |
| File | toFile() | Path→File |
| Path | toRealPath(LinkOption... options) | |
| String | toString() | 返回该Path对应的String |
| URI | toUri() | 返回该Path对应的URI |
正规路径:不含.和..的绝对路径
3、方法说明
最常用:
Path→String:p.toString()
Java:Path与Paths的更多相关文章
- Java的Path、Paths和Files
前言 因为这几天被java.nio的这几个接口和工具类卡到了,就顺便地查了一波文档以及使用方法,这篇其实更像是API的复制粘贴,只不过我在注释里多写了一些output和注意事项,看不惯API的可以选择 ...
- 什么是java path环境变量
参考:https://docs.oracle.com/javase/tutorial/essential/environment/paths.html 从orcle官网的文档中可以看到java pat ...
- java IO流 (九) Path、Paths、Files的使用
1.NIO的使用说明:>Java NIO (New IO,Non-Blocking IO)是从Java 1.4版本开始引入的一套新的IO API,可以替代标准的Java IO AP.>NI ...
- [Leetcode][JAVA] Path Sum I && II
Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that addi ...
- Ubuntu下增加eclipse菜单图标并配置java path(解决点击图标不能启动eclipse的问题)
Ubuntu下增加eclipse菜单图标 Ubuntu的菜单图标在/usr/share/applications目录下. 1. 在/usr/share/applications目录下新建eclipse ...
- java path
static{ String path = new Object(){ public String getPath() { return this.getClass().getResource(&qu ...
- LeetCode第[62]题(Java):Unique Paths 及扩展
题目:唯一路径(机器人走方格) 难度:Medium 题目内容: A robot is located at the top-left corner of a m x n grid (marked 'S ...
- NIO.2中Path、 Paths、Files类的使用
- Java NIO教程 文件系统
在NIO.2的文件系统中,Path是一切操作的基础.Path准确来说,代表着文件系统中的位置.可以代表一个目录(也就是通常所说的文件夹),也可以代表一个文件. 在新文件系统中,还有一个不得不说的就是F ...
随机推荐
- linux正则转换csv文件
- 开发升讯威在线客服系统启示录:怎样编写堪比 MSDN 的用户手册
本系列文章详细介绍使用 .net core 和 WPF 开发 升讯威在线客服与营销系统 的过程. 免费在线使用 & 免费私有化部署:https://kf.shengxunwei.com 文章目 ...
- 尚硅谷全套课件整理:Java、前端、大数据、安卓、面试题
目录 Java 尚硅谷 IT 精英计划 JavaSE 内部学习笔记.pdf 尚硅谷 Java 基础实战之银行项目.pdf 尚硅谷 Java 技术之 JDBC.pdf 尚硅谷 Java 技术之 Java ...
- .NET Core分析程序集最优美的方法,不用Assembly.LoadFile(),超越ReflectionOnlyLoad
在编写.NET程序的时候,如果需要对一个程序集文件进行分析,我们可以使用Assembly.LoadFile()来加载这个程序集,然后对LoadFile()方法返回的Assembly对象进行进一步的分析 ...
- python编写购物车
上次的学习又没有坚持下来,工作忙的不可开交,但我反思了一下还是自己没有下定决心好好学习,所以这次为期3个月的学习计划开始了,下面是这次学习后重新编写的购物车初版代码. 1 # 功能要求: 2 # 要求 ...
- 解决死锁之路3 - 常见 SQL 语句的加锁分析 (转)
出处:https://www.aneasystone.com/archives/2017/12/solving-dead-locks-three.html 这篇博客将对一些常见的 SQL 语句进行加锁 ...
- python基础篇-爬虫urlparse使用及简单示例
>>> from urllib.parse import urlparse >>> o = urlparse('http://www.cwi.nl:80/%7Egu ...
- 利用纯代码写出一个秒表表盘的方法 —— #DF
@interface ViewController () @property (nonatomic, strong) CALayer *secLayer; // 秒针layer @property ( ...
- docker错误处理——docker Job for docker.service failed because the control process exited with error code.
(15条消息) docker Job for docker.service failed because the control process exited with error code._Hel ...
- postman项目接口文档和登录步骤原理
培训内容 实训项目:非常果岭-发现模块接口测试,单接口.流程脚本编写: 使用工具:postman 培训方式 1)postman使用说明 2)项目接口文档和登录步骤原理 一.首先了解postman使 ...