java Path

介绍

Path用于来表示文件路径和文件,搭配 java.nio包下的类使用,如:Files

创建对象

可以有多种方法来构造一个Path对象来表示一个文件路径,或者一个文件

Paths

Path path = Paths.get("C:/", "Xmp");
Path path2 = Paths.get("C:/Xmp");

URI u = URI.create("file:///C:/Xmp/dd");
Path p = Paths.get(u);

FileSystems

Path path3 = FileSystems.getDefault().getPath("C:/", "access.log");

File

File file = new File("C:/my.ini");
Path p1 = file.toPath();

原文出处:/show_1IX1bBAG3YcD.html