• 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 text to a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Appending text to a file


  • Subject: Re: Appending text to a file
  • From: Martin Weil <email@hidden>
  • Date: Sun, 11 Aug 2002 22:07:07 +0200

Hi!
How can I append a string to a file ? I mean I don't want to overwrite the
entire file, but just adding my text at its end.

Thanks
Nico


NSFileHandle *aFileHandle;
NSString *aFile;

aFile = [NSString stringWithString:@"Your File Path"]; //setting the file to write to
aFile = [logFile stringByExpandingTildeInPath];

aFileHandle = [NSFileHandle fileHandleForWritingAtPath:aFile]; //telling aFilehandle what file write to
[aFileHandle truncateFileAtOffset:[aFileHandle seekToEndOfFile]]; //setting aFileHandle to write at the end of the file

[aFileHandle writeData:[toBeWritten dataUsingEncoding:nil]]; //actually write the data

For more Information see Documentation---Foundation---NSFileHandle

Hope this helps!

Regards,
Martin
--
http://www.mweil.net
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Appending text to a file (From: Nico <email@hidden>)

  • Prev by Date: Appending text to a file
  • Next by Date: Re: Appending text to a file
  • Previous by thread: Appending text to a file
  • Next by thread: Re: Appending text to a file
  • Index(es):
    • Date
    • Thread