Solved

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

Posted on 2002-06-14
2
332 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 108
diffSum example 4 37
fibonacci ten numbers 4 39
hibernate example for saving data 19 43
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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.

831 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