Studiewijzer module 09
NIO.2
-
Files.lines()levert eenStream<String>op. -
Files.readAllLines()levert eenList<String>op. -
Files.isSameFile(p1,p2)controleert of er echt naar hetzelfde pad gewezen wordt. Er wordt dus niet gecontroleerd of een bestand identiek is. -
In het geval van een
isSamePath()geeft deequals()ook eentrueterug.
Normalize
The normalize method removes any redundant elements, which includes any "." or "directory/.." occurrences. Both of the preceding examples normalize to /home/joe/foo.
It is important to note that normalize doesn’t check at the file system when it cleans up a path. It is a purely syntactic operation. In the second example, if sally were a symbolic link, removing sally/.. might result in a Path that no longer locates the intended file.
Relativize
-
Path p1 = Paths.get("home");
-
Path p3 = Paths.get("home/sally/bar");
-
// Result is sally/bar
-
Path p1_to_p3 = p1.relativize(p3);
-
// Result is ../..
-
Path p3_to_p1 = p3.relativize(p1);
Find
Files.find(start, maxDepth, matcher, options). De MaxDepth is om
lussen de voorkomen bij symbolic links.
De FileVisitOptions kunnen alleen een FOLLOW_LINKS zijn.
In tegenstelling tot de find() uit java.io.File is de matcher geen
Predicate< File >, maar een BiPredicate< Path, BasicFileAttributes
>.
« Vorige module Volgende module »