Creating an absolute path can be accomplished by explicitly specifying the root directory and all other subdirectories that contain the file or folder, as shown in the following examples (C:learningpacktJavaModernChallenge.pdf):
Path path = Paths.get("C:/learning/packt", "JavaModernChallenge.pdf");
Path path = Paths.get(
"C:", "learning/packt", "JavaModernChallenge.pdf");
Path path = Paths.get(
"C:", "learning", "packt", "JavaModernChallenge.pdf");
Path path = Paths.get("C:/learning/packt/JavaModernChallenge.pdf");
Path path = Paths.get(
System.getProperty("user.home"), "downloads", "chess.exe");
Path path = Path.of(
"C:", "learning/packt", "JavaModernChallenge.pdf");
Path path = Path.of(
System.getProperty("user.home"), "downloads", "chess.exe");
Path path = Paths.get(URI.create(
"file:///C:/learning/packt/JavaModernChallenge.pdf"));
Path path = Path.of(URI.create(
"file:///C:/learning/packt/JavaModernChallenge.pdf"));