We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

How does RandomFileAccess lock at the OS level?

jjacksn
jjacksn asked
on
Medium Priority
257 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?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
>>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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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?
CERTIFIED EXPERT
Top Expert 2016

Commented:
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
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.

Author

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 SPrincipal Technologist
CERTIFIED EXPERT
Commented:
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)?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.