2.2.2 从 Path 中获取信息
2016-01-06 10:20
211 查看
Demo:
Ran As Java Application:
import java.nio.file.Path; import java.nio.file.Paths; public class PathInfoTest { public static void main(String[] args) { // 创建绝对路径(位置) Path listing = Paths.get("/Users/jinxing/Documents/pathtest"); System.out.println("File Name: " + // 位置(文件)名称 listing.getFileName()); System.out.println("Number of Name Elements in the Path: " + // (位置)路径层级 / 元素数量 listing.getNameCount()); System.out.println("Parent Path: " + // 上级位置 / 上级文件路径 listing.getParent()); System.out.println("Root of Path: " + // 跟位置(路径) listing.getRoot()); System.out.println("Subpath from Root,2 elements deep: " + // 截断路径——从第1个反斜杠开始截取到第3个反斜杠——反斜杠计数从0开始——结果不包含头尾反斜杠 // /Users/jinxing/Documents/pathtest --> jinxing/Documents listing.subpath(1, 3)); } }
Ran As Java Application:
File Name: pathtest Number of Name Elements in the Path: 4 Parent Path: /Users/jinxing/Documents Root of Path: / Subpath from Root,2 elements deep: jinxing/Documents
相关文章推荐
- mysql性能监控
- [Egret学习笔记 十]ResDepot使用说明小技巧
- Redis和Memcache对比及选择
- OOM(3)
- SpringAOP之helloworld
- iOS 手机号正则表达式
- mvn常用命令
- MAMP添加mysql的环境变量
- Android:图形(二)
- PHP文件解压,压缩文件遍历,文件夹遍历
- 一次bug死磕经历之Hbase堆内存小导致regionserver频繁挂掉
- C# Windows - 菜单栏和工具栏
- Android中跨进程通讯的4种方式
- Android库工程及代码混淆(project.properties、proguard-project.txt)
- 罗胖的营销
- 导航条
- [Phonegap+Sencha Touch] 移动开发75 继承Number数字输入控件,实现四舍五入到指定小数位
- Windows media encoder 搭建流媒体服务器
- Docker容器修改hosts文件重启不变
- Linux中的工作队列