Re: crash during file writing, how to recover ?
From: Calum (calum.bulk_at_ntlworld.com)
Date: 05/02/04
- Next message: Soren Kuula: "Re: Bin Ladin Captured"
- Previous message: PlasmaDragon: "Re: Bin Ladin Captured"
- In reply to: Chris Smith: "Re: crash during file writing, how to recover ?"
- Next in thread: Roedy Green: "Re: crash during file writing, how to recover ?"
- Reply: Roedy Green: "Re: crash during file writing, how to recover ?"
- Reply: Corey Murtagh: "Re: crash during file writing, how to recover ?"
- Reply: Chris Sonnack: "Re: crash during file writing, how to recover ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 01 May 2004 23:59:52 +0100
Chris Smith wrote:
> Not surprisingly, it's not specified whether File.renameTo results in a
> call to the rename system call. More surprisingly, it's not specified
> whether File.renameTo will succeed if a file already exists by the
> target name. That said, renameTo returns a success flag (which is ugly
> in Java, but nevertheless happens). So it's entirely possible to write:
>
> if (!newFile.renameTo(fileBeingProcessed))
> {
> fileBeingProcessed.delete();
> newFile.renameTo(fileBeingProcessed);
> }
Just to be inconsistent, the Microsoft "rename" function specifically
requires "The new name must not be the name of an existing file or
directory". It makes some sense - I wouldn't expect a function called
"rename" to delete a file, but I can see situations where either
behaviour would be desired.
So it's possible Java will have different behaviour on Windows and
POSIX, though I can't be bothered to check this.
I guess for ultra-safety, the old file could be renamed to something
else, before renaming the new file to the target filename. Of course
then you'd just clutter up the directory with old files, but there are
circumstances where you want to be able to roll back.
Calum
- Next message: Soren Kuula: "Re: Bin Ladin Captured"
- Previous message: PlasmaDragon: "Re: Bin Ladin Captured"
- In reply to: Chris Smith: "Re: crash during file writing, how to recover ?"
- Next in thread: Roedy Green: "Re: crash during file writing, how to recover ?"
- Reply: Roedy Green: "Re: crash during file writing, how to recover ?"
- Reply: Corey Murtagh: "Re: crash during file writing, how to recover ?"
- Reply: Chris Sonnack: "Re: crash during file writing, how to recover ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|