Skip navigation.
 
mlRE: Appending to file with writeToFile
FROM : Glover,David
DATE : Thu May 29 17:23:02 2008

Thank you for your advice - I used your suggestion plus using
seekToEndOfFile beforehand worked a treat.

Thanks again

-----Original Message-----
From: Ken Thomases [mailto:<email_removed>]
Sent: 29 May 2008 16:08
To: Glover,David
Cc: <email_removed>
Subject: Re: Appending to file with writeToFile

On May 29, 2008, at 9:42 AM, Glover,David wrote:

> I'm using writeToFile to send strings to a log file at various 
> points in
> my program, however it doesn't append the strings, it just overwrites
> the previous one.  So the only thing in the log file is the very last
> string that was sent to it.


Yes.  The writeToFile:... methods mean "create a file with the 
receiver as its contents".  It isn't for incremental building of a 
file, but for wholesale creation of a file.


> I've searched around for a while and can't find any way to append the
> strings in my file.  I was wondering if anyone else had achieved this?
> Or if anybody knows how to do it?


Use NSFileHandle.  For example:

   NSFileHandler* fh = [NSFileHandle 
fileHandleForWritingAtPath:myOutputFilePath];

   // ...

   [fh writeData:[myString
dataUsingEncoding:NSUTF8StringEncoding]];

Cheers,
Ken

Promethean Limited is a company registered in England and Wales with company number 1308938 and VAT number GB 572 2599 18
______________________________________________

Promethean Ltd and or associated and or subsidiary companies :

The views expressed in this communication may not necessarily be
the views held by Promethean Ltd and or associated and or subsidiary companies.

This e-mail is for the exclusive use of the addressee(s). Unauthorised
disclosure, copying or distribution is prohibited.

This e-mail message has been swept for the presence of computer viruses.

Promethean Ltd and or associated and or subsidiary companies accepts no liability for any loss resulting from this email transmission.

Promethean, Promethean House, Lower Philips Road, Blackburn, Lancashire, BB1 5TH, UK. Please update your records accordingly. Thank you!



*****************************************************************
This email has been checked by the e-Sweeper Service
*****************************************************************

Related mailsAuthorDate
mlAppending to file with writeToFile Glover,David May 29, 16:42
mlRe: Appending to file with writeToFile Jens Alfke May 29, 17:03
mlRe: Appending to file with writeToFile Ken Thomases May 29, 17:07
mlRE: Appending to file with writeToFile Glover,David May 29, 17:23