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?
Who is Participating?
>>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
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?
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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)?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.