On Fri, 30 Apr 2004 18:25:02 +0200, Kasper Dupont
<> wrote or quoted :
>No need to delete the old one first. Renaming will
>automatically delete the old file.
Here is the sort of code I use to rewrite the contents of a file.
// create a tempfile in the same directory as
// the input file we have just processed.
File tempfile = HunkIO.createTempFile ("temp", ".tmp",
fileBeingProcessed );
FileWriter emit = new FileWriter( tempfile );
emit.write( result );
emit.close();
// successfully created output in same directory as input,
// Now make it replace the input file.
fileBeingProcessed.delete();
tempfile.renameTo( fileBeingProcessed );
This effectively makes the tempfile disappear, but without the delete
it would not make the old version disappear. Or would it?
It would be nice to have the delete/rename atomic.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See
http://mindprod.com/jgloss/jgloss.html for The Java Glossary.