Practice · 1 of 2
Path arithmetic, executed
CHALLENGE
Difficulty: advanced+25 XP
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.)
Press Submit to check your solution.
Back to lesson: Practice: File I/O drills