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
35 lines (25 loc) · 1.12 KB
/
Main.java
File metadata and controls
35 lines (25 loc) · 1.12 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
package modern.challenge;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) throws IOException {
Path path = Paths.get("/learning/packt", "JavaModernChallenge.pdf");
String pathToString = path.toString();
System.out.println("Path to String: " + pathToString);
URI pathToURI = path.toUri();
System.out.println("Path to URI: " + pathToURI);
Path pathToAbsolutePath = path.toAbsolutePath();
System.out.println("Path to absolute path: " + pathToAbsolutePath);
Path path2 = Paths.get("/learning/books/../PACKT/./", "JavaModernChallenge.pdf");
Path realPath = path2.toRealPath(LinkOption.NOFOLLOW_LINKS);
System.out.println("Path to 'real' path: " + realPath);
File pathToFile = path.toFile();
Path fileToPath = pathToFile.toPath();
System.out.println("Path to file name: " + pathToFile.getName());
System.out.println("File to path: " + fileToPath);
}
}