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 = ; 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

  

05-11 22:47