?
Solved

How does RandomFileAccess lock at the OS level?

Posted on 2006-03-30
8
Medium Priority
?
243 Views
Last Modified: 2008-03-10
If I open a filed using the RandomFileAccess command and "rw", will the OS stop the file from being written to by any other program?  will a subsequent call using "rw" fail?  

Would this differ between windows and *nix?
0
Comment
Question by:jjacksn
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 672 total points
ID: 16334406
>>will the OS stop the file from being written to by any other program?

I don't think you can guarantee that. Test it though
0
 
LVL 5

Author Comment

by:jjacksn
ID: 16336328
Ug.... I can't seem to do this simple thing:  

in the simplest case, I want to open a file what to open a file such that no one else can write to it while it is open... I know you can do this in windows, at least.  

However, calling


raf = new RandomAccessFile(fileName, "rw");
raf = new RandomAccessFile(fileName, "rw");

works... so that's not going to do it.  does the normal File object?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16336429
0
Industry Leaders: 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 92

Assisted Solution

by:objects
objects earned 664 total points
ID: 16336771
FileLock's aren't going to achieve what u need.
You could rename the file to a temporary file anem before you open it for writing, and then rename it back once done. That would stop anyone else accessing the file.
0
 
LVL 5

Author Comment

by:jjacksn
ID: 16337049
objects, that's great thanks.
 
I do know, at least in windows, that I've been looking at a file, and then tried to right to it, and it was "locked" by another program.  I don't mind if someone is reading the old data, so long as that don't to write to it until the first method call finished.  Can this be accomplished?  
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 664 total points
ID: 16339596
If the file has been opened for editing by any process, I don't think the OS will let another process modify it (whatever kind of file it is)?
0

Featured Post

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!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.
Suggested Courses

850 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