• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Appending to file with writeToFile
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Appending to file with writeToFile


  • Subject: Re: Appending to file with writeToFile
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 29 May 2008 10:07:45 -0500

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
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • RE: Appending to file with writeToFile
      • From: "Glover,David" <email@hidden>
References: 
 >Appending to file with writeToFile (From: "Glover,David" <email@hidden>)

  • Prev by Date: Re: 10.5.3 Release Notes?
  • Next by Date: RE: Appending to file with writeToFile
  • Previous by thread: Re: Appending to file with writeToFile
  • Next by thread: RE: Appending to file with writeToFile
  • Index(es):
    • Date
    • Thread