forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
36 lines (25 loc) · 1.02 KB
/
Copy pathMain.java
File metadata and controls
36 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package modern.challenge;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
// fix path
Path base1 = Paths.get("D:/learning/packt");
Path path1 = base1.resolve("JBossTools3.pdf");
System.out.println(path1);
Path path2 = base1.resolve("MasteringJSF22.pdf");
System.out.println(path2 + "\n");
Path basePath = Paths.get("D:/learning/packt");
String[] books = {"Book1.pdf", "Book2.pdf", "Book3.pdf"};
for (String book : books) {
Path nextBook = basePath.resolve(book);
System.out.println(nextBook);
}
// fix path
Path base2 = Paths.get("D:/learning/packt/JavaModernChallenge.pdf");
Path path3 = base2.resolveSibling("MasteringJSF22.pdf");
System.out.println("\n" + path3);
Path path4 = base2.getParent().resolveSibling("publisher").resolve("MyBook.pdf");
System.out.println("\n" + path4);
}
}