learning java Paths Path

import java.nio.file.Path;
import java.nio.file.Paths;

public class PathTest {
    public static void main(String[] args) throws Exception {
        Path path = Paths.get(".");
        System.out.println("path里包含的路径数目" + path.getNameCount());
        System.out.println("path的根路径" + path.getRoot());

        Path absolutionPath = path.toAbsolutePath();
        System.out.println(absolutionPath);

        System.out.println("absolution里的根路径:" + absolutionPath.getRoot());
        System.out.println("absolution里的路径数目:" + absolutionPath.getNameCount());

        for (int i = 0; i < absolutionPath.getNameCount(); i++){
            System.out.println(absolutionPath.getName(i));
        }


        Path path2 = Paths.get("g:", "publish", "codes");
        System.out.println(path2);

    }
}

output:

path里包含的路径数目1
path的根路径null
C:\Users\admin\IdeaProjects\learningJava\.
absolution里的根路径:C:\
absolution里的路径数目:5
Users
admin
IdeaProjects
learningJava
.
g:\publish\codes

  

posted @ 2019-08-06 11:04  嵌入式实操  阅读(273)  评论(0编辑  收藏  举报