forked from lokeshgupta1981/Core-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilePath.java
More file actions
31 lines (24 loc) · 815 Bytes
/
FilePath.java
File metadata and controls
31 lines (24 loc) · 815 Bytes
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
package com.howtodoinjava.io;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
public class FilePath {
public static void main(String[] args) throws IOException {
File file = new File("com/howtodoinjava/io/foo/bar/../foo.txt");
//1
String givenPath = file.getPath();
String absPath = file.getAbsolutePath();
String canPath = file.getCanonicalPath();
System.out.println(givenPath);
System.out.println(absPath);
System.out.println(canPath);
//2
Path path = Path.of("com/howtodoinjava/io/foo/bar/../foo.txt");
givenPath = path.toString();
absPath = path.toAbsolutePath().toString();
canPath = path.toRealPath().toString();
System.out.println(givenPath);
System.out.println(absPath);
System.out.println(canPath);
}
}