Studiewijzer module 09
NIO.2


  • Files.lines() levert een Stream<String> op.

  • Files.readAllLines() levert een List<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 de equals() ook een true terug.

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

  1. Path p1 = Paths.get("home");

  2. Path p3 = Paths.get("home/sally/bar");

  3. // Result is sally/bar

  4. Path p1_to_p3 = p1.relativize(p3);

  5. // Result is ../..

  6. 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 »