Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Is the file being written this moment?

Posted on 2004-10-24
Medium Priority
Last Modified: 2010-07-27

Is there anyway of knowing that a particular file is being written this moment OR  is opened by some application with "write" previliges.
Question by:engineer007
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 12397264

  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??
LVL 10

Expert Comment

ID: 12397372
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.


Author Comment

ID: 12397411
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!!
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 24

Accepted Solution

sciuriware earned 100 total points
ID: 12398127
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.

Expert Comment

ID: 12402904
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.

LVL 24

Expert Comment

ID: 12629256
LVL 24

Expert Comment

ID: 12654217
Forced thanks.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question