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

x
?
Solved

Is the file being written this moment?

Posted on 2004-10-24
9
Medium Priority
?
235 Views
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.
0
Comment
Question by:engineer007
[X]
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
9 Comments
 

Author Comment

by:engineer007
ID: 12397264
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
 
LVL 10

Expert Comment

by:NetworkArchitek
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.

Cheers!
0
 

Author Comment

by:engineer007
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!!
0
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

by:
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.
;JOOP!
0
 
LVL 2

Expert Comment

by:tdisessa
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.

 
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12629256
OK.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12654217
Forced thanks.
<*>
0

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