Is the file being written this moment?


Is there anyway of knowing that a particular file is being written this moment OR  is opened by some application with "write" previliges.
engineer007Asked:
Who is Participating?
 
sciuriwareConnect With a Mentor Commented:
There is 2 solutions to this problem:
1) lock the file from the application that writes; have the other application(s) wait for the lock to be gone,
2) trigger possible readers from the writer: there are numerous ways to do that.
;JOOP!
0
 
engineer007Author Commented:
Explanation::

  I have two applications working on the same file. One application will write stuff on the file while the other one will copy the file to a different location and delete it from the original one. I executed a "file copy" procedure and was surprised to know that files can be copied to a different location at the same time they are being written. The result is "a corrupt file" at the copy location. So is there any way around u guys??
0
 
NetworkArchitekCommented:
Hi engineer007,
Sure, the "file" object has two methods which return boolean: canRead() and canWrite(). You should be able to use this for your application.

Cheers!
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
engineer007Author Commented:
Well no matter whether the file is being written orn't , canRead() and canWrite() both always return true. They aint seem to be doing my thing!!
0
 
tdisessaCommented:
Calling the constructor of either FileWriter or FileOutputStream with the File/filename as an argument
will throw an exception if the file is already opened for write by another process.

Check out the Constructors for FileWriter or FileOutputStream.

 
0
 
sciuriwareCommented:
OK.
0
 
sciuriwareCommented:
Forced thanks.
<*>
0
All Courses

From novice to tech pro — start learning today.