Creating a path relative to the file store root

A path that's relative to the current file store root (for example, C:/) must start with the file delimiter. In the following examples, if the current file store root is C, then the absolute path is C:learningpacktJavaModernChallenge.pdf:

Path path = Paths.get("/learning/packt/JavaModernChallenge.pdf");
Path path = Paths.get("/learning", "packt/JavaModernChallenge.pdf");

Path path = Path.of("/learning/packt/JavaModernChallenge.pdf");
Path path = Path.of("/learning", "packt/JavaModernChallenge.pdf");

Path path = FileSystems.getDefault()
.getPath("/learning/packt", "JavaModernChallenge.pdf");
Path path = FileSystems.getDefault()
.getPath("/learning/packt/JavaModernChallenge.pdf");

Path path = Paths.get(
URI.create("file:///learning/packt/JavaModernChallenge.pdf"));
Path path = Path.of(
URI.create("file:///learning/packt/JavaModernChallenge.pdf"));

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.93.64