It's probably safer to delete. I haven't tested, and I don't know if
this is true, but maybe it actually overwrites instead of replacing,
i.e. if you write 1 line to a 2 line file, it may still have the old
2nd line. Anyway, I don't know if that's true or not. But to be on the
safe side, I always delete.
Of course, the safest manner is to write to a temporary file and then
swap the contents with the real file (easily done through the Carbon
Declare Library), but for saving to simple text files that's probably
overkill.
On Friday, August 30, 2002, at 12:15 PM, Steve Schacht wrote:
Let's say I have a valid reference to a FolderItem for a document
that's
currently being edited by a user. This document has already been saved
previously. So then the user makes some changes, and the dirty flag
is set.
Now the user selects "Save". When I save the document, I'm writing
out the
entire file (as a text stream) each time. My question is... Should I
be
deleting the existing file before saving? My testing has indicated
that
this is not necessary - i.e. that I can just re-open the text stream
and
overwrite what's there - but I wanted to know if this is bad practice
for
any reason.
--
Kevin Ballard
kevin at sb dot org
http://www.tildesoft.com
Email from Korea or China must go to <kevin dot nb at sb dot org>
|