How does RandomFileAccess lock at the OS level?

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?
LVL 5
jjacksnAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jjacksnAuthor Commented:
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?
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Mick BarryJava DeveloperCommented:
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.
jjacksnAuthor Commented:
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?  
Mayank SAssociate Director - Product EngineeringCommented:
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)?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.