提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取路径根,父元素
import java.nio.file.Path; import java.nio.file.Paths; /** 时 代 Java - nowjava.com 提 供 **/ public class Main { public static void main(String[] args) { Path path = Paths.get("C:", "folder1/folder2/folder4", "test.txt"); System.out.println("The file/directory indicated by path: " + path.getFileName()); System.out.println("Root of this path: " + path.getRoot()); System.out.println("Parent: " + path.getParent()); System.out.println("Number of name elements is path: " + path.getNameCount()); for (int i = 0; i < path.getNameCount(); i++) { System.out.println(