• 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

File Change Detection Question

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm currently using the file change detection resource that was added in Java 7 in the nio package and I'm a little confused by the results that I'm getting.

I broke down the detection to the simplest format to get pure results, but the results I get don't make sense to me.

This is the code that I am using to simply print out when a file in the current directory is changed and what kind of change occurred; created, deleted, or modified. It works, but there seem to be strange/differing results from Linux to Windows


In linux it prints the following when the file "text.txt" is edited, and doesn't print anything if a blank file is created or deleted

File Name: test.txt
File Path: /home/patrick/workspace2/Test/.
Event Kind: ENTRY_MODIFY



In windows it prints the same whenever a file is edited or deleted and still doesn't print anything when a blank one is created

Stranger still, when a file is edited with gedit it prints the following

File Name: .goutputstream-CV8LKX
File Path: /home/patrick/workspace2/Test/.
Event Kind: ENTRY_MODIFY



Is there any possible way to reconcile this behaviour? The differences from Windows to Linux are acceptable, but I really need to be able to access the correct file name.

Thanks a lot for your help
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you edit with gedit (and other similar editors) they usually create a (hidden) temporary file for the session. The .goutputstream-CV8LKX is probably one such file and since it gets newly created by gedit it shows up in the events of the WatchService. I however haven't played much with these APIs so I can't really say why it shows up a ENTRY_MODIFY and why you aren't seeing events for newly created blank files.

 
Rancher
Posts: 43081
77
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

doesn't print anything if a blank file is created or deleted


Just stating the obvious, but is that the case even if the respective flags are not commented out (as they currently are)?

Regarding the temporary file: that just goes to show that no other process should use a directory you're watching, as various apps create temporary files. Or you can just filter out invisible files.
 
patrick Vares
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:

doesn't print anything if a blank file is created or deleted


Just stating the obvious, but is that the case even if the respective flags are not commented out (as they currently are)?

Regarding the temporary file: that just goes to show that no other process should use a directory you're watching, as various apps create temporary files. Or you can just filter out invisible files.



You were absolutely right about the flags being commented out...

When they are uncommented it behaves as I would expect it to

(when edited through gedit)

File Name: .goutputstream-X3GEKX
File Path: /home/patrick/workspace2/Test/.
Event Kind: ENTRY_CREATE
File Name: .goutputstream-X3GEKX
File Path: /home/patrick/workspace2/Test/.
Event Kind: ENTRY_MODIFY
File Name: .goutputstream-X3GEKX
File Path: /home/patrick/workspace2/Test/.
Event Kind: ENTRY_DELETE
File Name: test.txt
File Path: /home/patrick/workspace2/Test/.
Event Kind: ENTRY_CREATE



Thank you both for your help, I think I can work with this now that it's clear how gedit is handling the files
 
reply
    Bookmark Topic Watch Topic
  • New Topic