Skip to main content

File system watcher - problems on Windows

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
4 replies [Last post]
violetagg
Offline
Joined: 2011-01-24

Hi,

We have implemented a file system watcher. It is working pretty good on Linux and MAC but we have the following problem on Windows.

When a big file is copied on FS, I'm receiving an event that a file is created. I'm checking the last modified attribute on regular intervals in order to understand whether the copying is finished or not. Unfortunately the last modified attribute is not changing. It is set once and that's all.

My question is: how to understand that the file copying is finished.

I know that there is File system watcher in Java SE 7, but we still use Java SE 6.

Thanks in advance
Violeta

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
eskatos
Offline
Joined: 2007-05-14

You could check that its size is not growing.

Simple suggestion, pretty ugly tough.

/Paul

violetagg
Offline
Joined: 2011-01-24

Unfortunately I can see that the last modified and the length attributes are set at the beginning of the copy operation. They are not changed any more, even when the copy operation finishes.

imsomeroy
Offline
Joined: 2011-09-09

Instead of checking size or modified time, simple rename the file to it's self. If the rename fails, the file is still in use by the copy. If the rename is successful, the file is no longer busy as the copy has completed. Regardless of success or failure of the rename call, there is no cleanup.

violetagg
Offline
Joined: 2011-01-24

It is working perfect. Thanks a lot.