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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

engineer007Author Commented:

  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??
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.

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!!
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

Forced thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.