I encountered this problem while working with the Watch Service API in Java 7. I registered a directory with Watch Service to be able to monitor any new files begin created/uploaded via copy or FTP method. The watch service kicks in as soon as it receives the watch key. However, after I obtain the context from the Watch Event when I try to read the file I get "java.io.FileNotFoundException: C:\Documents and Settings\TestUser\logs\test.log (The process cannot access the file because it is being used by another process)
at java.io.FileInputStream.open(Native Method)
Has any one come across similar problem? All suggestions and advices are welcome.
Thanks in Advance!
Exactly what are you expecting here? The error you get seems like standard operating system blab you would get when applications concurrently try to access the same file. Windows is very good at locking stuff down. If this is a problem for you, use Linux which handles it far better.
Yes it was the locking issue (Operating systems would enforce a lock on file transfer). I figured that just a couple minutes ago. To fix this issue, I had to refresh the file's attributes recursively to identify the status of transfer.
There is this api in apache commons IO " FileEntry ", it has a method called refresh(File <file_name>); It helped me figure the status of the transfer.
Thanks for all your help.
Edited by: user538423 on Aug 31, 2012 12:02 PM