2.2.4 转换 Path
在NIO.2里可以很容易地合并Path,在两个Path中再创建Path或对Path进行比较;
Demo:
import java.nio.file.Path;
import java.nio.file.Paths; public class PathConvert { public static void main(String[] args) { // 两个[Max OS X]路径
Path path1 = Paths.get("/Users/jinxing/Documents/pathtest/path1");
Path path2 = Paths.get("/Users/jinxing/Documents/pathtest/path2"); // 合并:被合并位置前不加分隔符
Path completePath12 = path1.resolve("ss/ss"); // 距离:两个Path之间的路径
Path path1ToPath2Dir = path1.relativize(path2); // show
System.out.println(completePath12);
System.out.println(path1ToPath2Dir); // 比较:equals[Path.toString()-两个字符串之间的比较]
System.out.println(completePath12.toString().equals("/Users/jinxing/Documents/pathtest/path1/ss/ss"));
// 比较:startsWith[Path间比较|完整文件名](以...开头)
System.out.println(path1.startsWith("/Users"));
// 比较:endsWith[Path间比较|完整文件名|前不加分隔符](以...结尾)
System.out.println(path2.endsWith("pathtest/path2")); // [略]更多比较测试:如Path.equals(Path) } }
Ran As Java Application:
/Users/jinxing/Documents/pathtest/path1/ss/ss
../path2
true
true
true
2.2.4 转换 Path的更多相关文章
- node之path模块
node之path模块 原文链接 //引用该模块 var path = require("path"); 1.路径解析,得到规范化的路径格式 对window系统,目录分隔为'', ...
- python os.path模块
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...
- os.path 大全
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回一个路径的最后一个组成部分 os.path.commonprefix(list) #返回 ...
- Python 中 os.path模板
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...
- python os.path模块--转载
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...
- 【python常用模块】os.path
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...
- Path.OS 模块的使用方法(转自DK的博客)
Python os.path模块 使用方法 os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonpref ...
- Python os.path模板函数
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...
- OS.path部分函数的介绍
OS.path模块中的部分函数的介绍 os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix( ...
随机推荐
- java 复用类的三种方式区别 组合,继承,代理的区别
1. 组合 : 只需在新类中产生现有类的对象 .(is - a 有一个) 新类是由现有类的对象组成. (引用初始化与作用域?) 2. 继承 : 按照现有类的类型来创造新类. (has - a 有一个) ...
- 《Java 并发编程实战》读书笔记之二:图文讲述同步的另一个重要功能:内存可见性
转载请注明出处:http://blog.csdn.net/ns_code/article/details/17288243 加锁(synchronized同步)的功能不仅仅局限于互斥行为,同时还存在另 ...
- Android ===smail语法总结
(转载自 网络)smail 语法总结 http://www.blogjava.net/midea0978/archive/2012/01/04/367847.html Smali背景: Smali,B ...
- 关于Form窗体的StartPosition 属性如何设置的问题
1.让窗体在启动时在指定位置出现 form1.StartPosition Manual CenterScreen WindowsDefaultLocation (default) WindowsDef ...
- XMPPFrameWork IOS 开发(一)xmpp简介
原始地址:XMPPFrameWork IOS 开发(一) XMPP : The Extensible Messaging and Presence Protocol 中文全称: 可扩展通讯和表示协议 ...
- 搜索-hdu-3720-Arranging Your Team
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3720 题目大意: 有23个人,告诉每个人的名字,能力值,以及踢球的位置.要求选出1个守门员,2个前锋 ...
- [PWA] 15. Using The IDB Cache And Display Entries
We want to use IDB to store the wittr messages. The logic is when the page start: service worker wil ...
- [Firebase] Deploy you website to Firebase
If you are looking for a host website, you can try Firebase, heroku or AWS... Today, I tried to depl ...
- 网络接口 使用NSURLConnection完成Get和Post方法
网络接口 使用NSURLConnection完成Get和Post方法 什么是URL: URL就是统一资源定位器(UniformResourceLocator:URL).通俗地说,它是用来指出某一项信息 ...
- iOS UI布局调试工具
查看ios软件的ui布局有三种: 1.DCIntrospect 这种方式是开源的,我从github上clone下来后运行demo,运行遇到了问题:Xcode cannot run using t ...