Re: append to file (new to Cocoa)
Re: append to file (new to Cocoa)
- Subject: Re: append to file (new to Cocoa)
- From: Matt Neuburg <email@hidden>
- Date: Fri, 08 Jul 2005 07:34:23 -0700
On Fri, 8 Jul 2005 18:50:44 +1000, Ron Fleckner <email@hidden>
said:
>Hi list,
>
>After searching the docs and the list archive, I haven't been able to
>find out how to append data (text in my case) to a file. I'm making
>a fairly simple game and want to allow users to keep a record of
>their scores. This is my workaround:
>
> // write new data to 'scores' file
> NSString *theNewScore = [NSString stringWithFormat:@"%d\n", aInt];
> NSError *err;
> NSString *fileContents = [NSString
>stringWithContentsOfFile:pathToFile];
> NSString *newFileContents = [fileContents
>stringByAppendingString:theNewScore];
> [newFileContents writeToFile:pathToFile atomically:YES
>encoding:NSASCIIStringEncoding error:&err];
>
>but is there a way I can simply append the text without first reading
>the whole file into a NSString variable and then using
>stringByAppendingString?
Would NSFileHandle be useful here? m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden