On page 632, the output doesn't correspond to what the code is doing.
The code to print the output is:
Now
path.getFileName() returns only the
farthest element from the root in the directory hierarchy, not the full absolute path.
Even if we were to change the code above to:
it still wouldn't print the full path from the root, as the path in question is relative to the directories being watched. In this specific example, the directories being watched are "/user/home/zoo/data" and "/user/home/zoo/log", so the paths returned by
watchEvent.context() would be relative to these, i.e.
NewFile.txt,
ZooData.txt, etc.
From the
WatchEvent API:
T context()
Returns the context for the event.
In the case of ENTRY_CREATE, ENTRY_DELETE, and ENTRY_MODIFY events the context is a Path that is the relative path between the directory registered with the watch service, and the entry that is created, deleted, or modified.