0

I am using JNotify to watch a folder, As soon as a new file comes into the folder, I need to parse that file and move the file in some other folder, When It executes the code of file movement "it is saying that it is used by some other process".

As this file was already watched by JNotify so I can't move it.

Please help me with some idea.

Oleg Mikheev
  • 17,186
  • 14
  • 73
  • 95
Sunny Gupta
  • 6,929
  • 15
  • 52
  • 80

2 Answers2

1

Your Java code must have an open file handle. Ensure any readers or other File objects are closed and garbage collected. I had the same problem and after analyzing the code I discovered that an InputStreamReader wasn't getting closed when an exception was caught. I added a finally{} block to the try catch block with a reader.close() and the problem was solved.

Abubakkar
  • 15,488
  • 8
  • 55
  • 83
Kevin
  • 11
  • 3
1

Starting from Java 7 you can use WatchService to track changes in file system.

If using Java 7 is an option in your case - I would definitely go for it.

The tutorial is very helpful and self explanatory.

Oleg Mikheev
  • 17,186
  • 14
  • 73
  • 95