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

x
?
Solved

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

Posted on 2002-06-14
2
Medium Priority
?
366 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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.
Suggested Courses

618 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