你的位置:首页 > 软件开发 > Java > 2.2.2 从 Path 中获取信息

2.2.2 从 Path 中获取信息

发布时间:2016-01-06 11:00:27
Demo:import java.nio.file.Path;import java.nio.file.Paths;public class PathInfoTest { public static void main(String[] args) { // ...

Demo:

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));      }}

原标题:2.2.2 从 Path 中获取信息

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录