• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Info about modifying watching a directory for change.

 
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI everyone,
I would like to know why I get the following when modifying a file on the Desktop.
The Desktop has been registered and all the process to retrieve the event when modified has been correctly implemented.
I get the following:



I did not create or delete anything however in the console appears at the end that something has been created (Widelec.txt~) then something else(goutputstream-N2FJ1W) deleted and then something else created (Widelec.txt);
Does it mean that for each modification of a file the OS delete and recreate the file itself?
My output is a result of using a program used in this Oracle java tutorial as demonstration purpose.
Furthermore when I rename a file it says first ENTRY_DELETE file.txt and then ENTRY_CREATE file.txt. Does it mean that for each renaming of a file, the file itself gets deleted and then recreated with the new name?

Thanks in advance.



 
Ranch Hand
Posts: 239
12
Scala IntelliJ IDE Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nick,

What were you using to create, delete, and modify those particular files? This may be more about the particular software in question than anything else. For instance, if you open a Microsoft Word document and start typing, before you actually save anything the stuff you are typing gets saved to a temporary file. This provides the document recovery feature that word has, where if you experience some kind of system crash, power outage, etc. when you open Word again, the stuff is still there in the document recovery window (I cannot remember off the top of my head for sure if it is called document recovery but it is something like that). So when you say "I did not create or delete anything...." maybe you didn't, directly, but your editor or whatever did.
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Scott Shipp wrote:Hi Nick,

What were you using to create, delete, and modify those particular files? This may be more about the particular software in question than anything else. For instance, if you open a Microsoft Word document and start typing, before you actually save anything the stuff you are typing gets saved to a temporary file. This provides the document recovery feature that word has, where if you experience some kind of system crash, power outage, etc. when you open Word again, the stuff is still there in the document recovery window (I cannot remember off the top of my head for sure if it is called document recovery but it is something like that). So when you say "I did not create or delete anything...." maybe you didn't, directly, but your editor or whatever did.




Hi Scott,
Hi can imagine the temporary file thing, however what about the last line ENTRY_CREATE Widelec.txt? The file was already present why the need to CREATE it again? and not just MODIFY?
I think all the goutputstream-N2FJ1W are chunk of data flushed out by an internal buffer. However still the last ENTRY_CREATE puzzles me a bit. Since the file Widelec.txt is already present and do not need to be created but modified at most.
Thanks for replying.

 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to be using 'gedit' to edit the text file /home/widelec/Desktop/Widelec.txt and then saving it using either ^S or the menu item File->Save . As I would expect, 'gedit' creates a temporary file containing your updated file content (in your case goutputstream-N2FJ1W) as part of the save to make sure the new file is written before deleting the old file. The file Widelec.txt file is renamed to Widelec.txt~ and then the temporary file is renamed to Widelec.txt . Your output seems consistent with this.

Since you are using Linux (or some other *Nix) renaming a file using 'mv' (to the same volume) does not change the file in any way, it just changes the directory entry. I suppose this makes the 'delete' followed by 'create' a little misleading but is acceptable to me since it does not actually change a files content; it only changes a directory entry. I bet you would get a very different output for 'mv' if you moved to a different volume.


 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Tookey wrote:You seem to be using 'gedit' to edit the text file /home/widelec/Desktop/Widelec.txt and then saving it using either ^S or the menu item File->Save . As I would expect, 'gedit' creates a temporary file containing your updated file content (in your case goutputstream-N2FJ1W) as part of the save to make sure the new file is written before deleting the old file. The file Widelec.txt file is renamed to Widelec.txt~ and then the temporary file is renamed to Widelec.txt . Your output seems consistent with this.

Since you are using Linux (or some other *Nix) renaming a file using 'mv' (to the same volume) does not change the file in any way, it just changes the directory entry. I suppose this makes the 'delete' followed by 'create' a little misleading but is acceptable to me since it does not actually change a files content; it only changes a directory entry. I bet you would get a very different output for 'mv' if you moved to a different volume.




Hi Richard,
So the file never gets deleted, it's just a trigger which triggers each time the file watched disappear right? Consider that it happens also when I move a file out of a folder. It triggers delete, so it would be safe saying that both DELETE and CREATE are just triggers related to when a file appear or disappear within the file system bit being watched with WatchService.
Am I right?

.
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Widelec wrote:
Hi Richard,
So the file never gets deleted, it's just a trigger which triggers each time the file watched disappear right? Consider that it happens also when I move a file out of a folder. It triggers delete, so it would be safe saying that both DELETE and CREATE are just triggers related to when a file appear or disappear within the file system bit being watched with WatchService.
Am I right?

.



The '~' file content and directory entry get deleted before a new '~' file is created. Moving a file out of a folder is not the same as moving it a different volume as only the directory entry changes. As to the detail of what the DELETE and CREATE events are you would need to find someone more knowledgeable than me if you want a definitive description. It could be that the DELETE and CREATE events are generated so that they are similar to what one gets in Windows.
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richard Tookey wrote:

Nick Widelec wrote:
Hi Richard,
So the file never gets deleted, it's just a trigger which triggers each time the file watched disappear right? Consider that it happens also when I move a file out of a folder. It triggers delete, so it would be safe saying that both DELETE and CREATE are just triggers related to when a file appear or disappear within the file system bit being watched with WatchService.
Am I right?

.



The '~' file content and directory entry get deleted before a new '~' file is created. Moving a file out of a folder is not the same as moving it a different volume as only the directory entry changes. As to the detail of what the DELETE and CREATE events are you would need to find someone more knowledgeable than me if you want a definitive description. It could be that the DELETE and CREATE events are generated so that they are similar to what one gets in Windows.




I see, So I think CREATE and DELETE are strictly referred to the directory entry. To enforce this thought, if I rename a file it triggers DELETE first and CREATE then.. even though obviously the content never gets touched. Whereas for MODIFY it should check for the present of those gooutputstream.. waiting for some confirmation if anybody feels like it would me much appreciated.
Thanks in advance.
 
Scott Shipp
Ranch Hand
Posts: 239
12
Scala IntelliJ IDE Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are right, but I don't have a reference for confirmation. I looked at the API on Oracle's site for WatchEvent and didn't see any clear definition of each event.
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Widelec wrote:Whereas for MODIFY it should check for the present of those gooutputstream..


The ".gooutputstream.xxxxxx" files are temporary files generated only by 'gedit'. Other applications will generated different temporary file names.
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot guys,
I see you are quite active on the forum, can I ask you a favour?
Basically I have opened this post on SCJP/OCPJP section, however I have not received any response yet. Not an issue at all maybe I mistook posting it there even though PathMatcher is in the topic exams.

https://coderanch.com/t/617963/java-programmer-SCJP/certification/related-PathMatcher-matches

Here it is it's basically just to copy and paste the code to see whether or not it returns false or true..
It should return true! however I get false...

Thanks in advance. And sorry for the off topic.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic