Question about OCJP 7 (804) related to WatchDirectory

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Question about OCJP 7 (804) related to WatchDirectory

Post by The_Nick »

So basically for the following code related to topic "Watching directory":

Code: Select all

for(WatchEvent<?> event:kC.pollEvents()){
			switch(event.kind().name()){
			case "OVERFLOW":
			System.out.println("We lost some events");
			break;
			case "ENTRY_CREATE":
			System.out.println("File " + event.context() + " has been modified!");
			break;
			case "ENTRY_MODIFY":
				System.out.println("File" + event.context()+ "has been modified!");
			case "ENTRY_DELETE":
				System.out.println("File" + event.context()+ "has been deleted!");
				
I have 2 questions:
1) What should happen to a directory to actually queue the events? how many file should be deleted together to make the method queue and return a real list instead of a single element?
2) How can we trigger the "ENTRY_MODIFY" case? I tried personally to modify the file name of a directory on my desktop and it gave me back a "previous file has been deleted" plus "renamed file has been created". What do they mean with ENTRY_MODIFY?I also tried to modified the file content and nothing.It still triggers first ENTRY_DELETE and then ENTRY_CREATE. How is it possible to trigger ENTRY_MODIFY?

Thanks in advance.

The_Nick.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: Question about OCJP 7 (804) related to WatchDirectory

Post by The_Nick »

Ehy OCJP7 takers Has anybody come across (while walkingFileTreeing) to the ENTRY_MODIFY getting trigged. If so, could you please provide me with an example? Thanks in advance.

The_Nick.

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Question about OCJP 7 (804) related to WatchDirectory

Post by admin »

You can try the sample program given here.

I added some more souts and here is the output that I get and I watch c:\temp\testdir
got key = sun.nio.fs.WindowsWatchService$WindowsWatchKey@2ab600af
Kind = ENTRY_DELETE
ENTRY_DELETE: c:\temp\testdir\dsf
Kind = ENTRY_CREATE
ENTRY_CREATE: c:\temp\testdir\dsf00
got key = sun.nio.fs.WindowsWatchService$WindowsWatchKey@2ab600af
Kind = ENTRY_MODIFY
ENTRY_MODIFY: c:\temp\testdir\dsf00
When I create something inside testdir\dsf00, I get ENTRY_MODIFY.

You need to play around with the above program and see how it works.

HTH,
Paul.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: Question about OCJP 7 (804) related to WatchDirectory

Post by The_Nick »

By using ubuntu and jdk 7 though when creating a new file in a watched folder I got a "ENTRY_CREATE" instead of an "ENTRY_MODIFY". Even though it should get an ENTRY_MODIFY why it does get an ENTRY_MODIFY instead of an ENTRY_CREATE if you had created something in that folder? What's the difference between ENTRY_MODIFY and ENTRY_CREATE? (I know that the name should say it all but it's quite confusing).

Thanks in advance.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests