About Question enthuware.ocpjp.v8.2.1673 :
Posted: Sun Nov 29, 2015 4:15 am
Given the following code for monitoring a directory:
Path path = Paths.get(directoryPath);
WatchService watchService = FileSystems.getDefault().newWatchService(); path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY,
StandardWatchEventKinds.ENTRY_DELETE);
while(true){
WatchKey key = watchService.take(); //waits until a key is available
System.out.println(key.isValid());
for (WatchEvent<?> watchEvent : key.pollEvents()) {
Kind<?> kind = watchEvent.kind();
System.out.println(kind); } }
A file is created and then deleted from the monitored directory.
How many events will be printed by the above code?
There are four option available.
A 1
B 2
C 3
D 4
Query - In questions above there is no system.out.println for printing events.
Answer is A - 1 event .
I would like to know , how 1 is came for said questions.
Path path = Paths.get(directoryPath);
WatchService watchService = FileSystems.getDefault().newWatchService(); path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY,
StandardWatchEventKinds.ENTRY_DELETE);
while(true){
WatchKey key = watchService.take(); //waits until a key is available
System.out.println(key.isValid());
for (WatchEvent<?> watchEvent : key.pollEvents()) {
Kind<?> kind = watchEvent.kind();
System.out.println(kind); } }
A file is created and then deleted from the monitored directory.
How many events will be printed by the above code?
There are four option available.
A 1
B 2
C 3
D 4
Query - In questions above there is no system.out.println for printing events.
Answer is A - 1 event .
I would like to know , how 1 is came for said questions.