Page 1 of 1

Question about OCJP 7 (804) related to WatchDirectory

Posted: Thu May 16, 2013 9:37 am
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.

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

Posted: Fri May 17, 2013 10:46 am
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.

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

Posted: Fri May 17, 2013 5:48 pm
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.

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

Posted: Sat May 18, 2013 2:01 am
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.