在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的更多相关文章

  1. node之path模块

    node之path模块 原文链接 //引用该模块 var path = require("path"); 1.路径解析,得到规范化的路径格式 对window系统,目录分隔为'', ...

  2. python os.path模块

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  3. os.path 大全

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回一个路径的最后一个组成部分 os.path.commonprefix(list) #返回 ...

  4. Python 中 os.path模板

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  5. python os.path模块--转载

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  6. 【python常用模块】os.path

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  7. Path.OS 模块的使用方法(转自DK的博客)

    Python os.path模块 使用方法 os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonpref ...

  8. Python os.path模板函数

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  9. OS.path部分函数的介绍

    OS.path模块中的部分函数的介绍 os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix( ...

随机推荐

  1. Linux kernel ‘ip6_sk_dst_check’函数拒绝服务漏洞

    漏洞名称: Linux kernel ‘ip6_sk_dst_check’函数拒绝服务漏洞 CNNVD编号: CNNVD-201307-070 发布时间: 2013-07-05 更新时间: 2013- ...

  2. POJ-1330--Nearest Common Ancestors(离线LCA)

    LCA离线算法 它需要一次输入所有的询问,然后有根节点开始进行深度优先遍历(DFS),在深度优先遍历的过程中,进行并查集的操作,同时查询询问,返回结果. 题意: 求A ,B两点的最近公共祖先 分析: ...

  3. redis数据过期策略【转】

    key的过期时间通常,Redis key被创建时不会自动关联过期时间,key将长久存在,除非通过DEL等命令显示的删除.EXPIRE命令簇可以为指定的key关联一个过期时间,代价是一点额外的内存开销. ...

  4. 数学(错排):BZOJ 4517: [Sdoi2016]排列计数

    4517: [Sdoi2016]排列计数 Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 693  Solved: 434[Submit][Status ...

  5. Permutations II ——LeetCode

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  6. Ubuntu 14.04 dnw配置

    之前写的Ubuntu嵌入式环境搭建没有讲怎么配置dnw下载工具,使用dnw还得用红帽,今天配置好了ubuntu下的dnw,记录一下 首先先下载dnw的源码,这是我上传的提供给大家下载:http://p ...

  7. floyd详解

    就不在来回搬了 请看 http://note.youdao.com/groupshare/?token=6422E952998F4381A1534B71359EFA57&gid=1579165 ...

  8. centos下的mysql安装

    卸载mysql yum remove mysql mysql-server mysql-libs compat-mysql51 rm -rf /var/lib/mysql rm /etc/my.cnf ...

  9. poj2239 Selecting Courses --- 二分图最大匹配

    匈牙利算法模板题 有n门课程,每门课程可能有不同一时候间,不同一时候间的课程等价. 问不冲突的情况下最多能选多少门课. 建立二分图,一边顶点表示不同课程,还有一边表示课程的时间(hash一下). #i ...

  10. LayoutInflater和inflate()方法的使用方法

    public static LayoutInflaterfrom(Context context) { LayoutInflaterLayoutInflater = (LayoutInflater)c ...