• Post Reply Bookmark Topic Watch Topic
  • New Topic

File Change Detection Question  RSS feed

 
patrick Vares
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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.

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!