?
Solved

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

Posted on 2002-06-14
2
Medium Priority
?
359 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
[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
2 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 600 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump 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 …
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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