Solved

how to check if a file is being written to in java

Posted on 2002-06-14
2
311 Views
Last Modified: 2008-03-06
I need to perform some operation on a file (e.g. move or delete), but NOT when it is currently being written to by some other process.

I believe this is easily done in "C".  Is there JAVA equivalent? (I checked java.io.File; it does not have what I need).  I would like to do this in pure JAVA, and not use JAVA/c.


0
Comment
Question by:happyloman
2 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 200 total points
ID: 7078440
I believe you would be able to determine whether a file is being written to, by trying to open it. Since writing is an inherently exclusive access operation, another process wouldn't be able to open it, so the open attempt should fail.

However, if the other "writing" process can happen at random, you can still have a problem in that in the time between your test and your operation (move or delete) the writing process could start up.......
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7078948
>>
I believe you would be able to determine whether a file is being written to, by trying to open it. Since
writing is an inherently exclusive access operation, another process wouldn't be able to open it, so
the open attempt should fail.
>>

This, I think, is true if you substitute 'move' or 'delete' for 'open' in the above sentence.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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 …

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now