Path
Đại diện cho path của file và folder

- absolute path: Path bao gồm cả root node
- relative path: không bao gồm root node, nhưng ngầm hiểu là liên quan đến folder hiện tại hoặc 1 thư mục nào đó, và nó không có đủ data để chỉ ra vị trí của file trong file system.
Một số system hỗ trợ symbolic links (aka symlink or soft link), refer đến 1 nơi khác. Việc sử dụng symbolic link hoàn toàn bình thường.

Một số method
- normalized(): chuẩn hoá lại path
Path p = Path.of("out/production/IOProject/../../../src/.");
System.out.println("Normalize transforms \n\t" + p.toString()
+ "\n to: \n\t" + p.normalize() + "\n---------------");
//OUTPUT:
//Normalize transforms
// out\production\IOProject\..\..\..\src\.
// to:
// src
p = Path.of("/a/../../../b/./../c");
System.out.println("Normalize transforms \n\t" + p.toString()
+ "\n to: \n\t" + p.normalize() + "\n---------------");
//OUTPUT
//Normalize transforms
// \a\..\..\..\b\.\..\c
// to:
// \c
- resolve(String), resolve(Path): return reference hiện tại nếu param empty, return kiểu như folder cha + con, nếu như param input không bao gồm đường dẫn root (bắt đầu bằng / hoặc tên ổ đĩa C:/ …), còn nếu bao gồm đường dẫn root thì tuỳ theo implement nên không đoán trước được.
- resolveSibling(String or Path): return path cùng cấp với path hiện tại nếu path hiện tại có parent, bằng không sẽ return path của param input
- relativize(Path): convert path input so với path hiện tại, return relative path
Relativize transforms
LearningAcademyOrg\IOProject\out\production
LearningAcademyOrg\ParallelStreams
to:
..\..\..\ParallelStreams
---------------
Relativize transforms
LearningAcademyOrg\ParallelStreams
LearningAcademyOrg\IOProject\out\production
to:
..\IOProject\out\production
---------------
Relativize transforms
garden\fruit\apple
pear
to:
..\..\..\pear
- compareTo(Path), compare 2 path, không truy cập file và không yêu cầu file tồn tại.
- startsWith(String or Path)
- endsWith(String or Path)
- toRealPath(LinkOptions…): return real path của 1 file tồn tại. Nếu path hiện tại là relative, return absolute path. Nếu path tồn tại element thừa, return path đã loại bỏ phần đó. Nếu LinkOption.NOFOLLOW_LINKS được input, method sẽ không follow sumbolic links.
