Skip to main content

Practice ยท 1 of 2

Path arithmetic, executed

1. static Path buildLogPath(Path base) โ€” return base.resolve("logs").resolve("app.log"). 2. static String relativeShape(Path base, Path child) โ€” return base.relativize(child).toString(). 3. static int nameCount(Path p) โ€” p.getNameCount(). 4. static boolean atomicSwap(Path src, Path dst) โ€” write "new" to src, then Files.move(src, dst, REPLACE_EXISTING); return true iff dst now contains "new" and src no longer exists. (Create dst with old content "old" first.)

Difficulty: advanced

Back to lesson: Practice: File I/O drills