3

Possible Duplicate:
iOS - appending to end of file with NSMutableString

Say I have a file at /var/mobile/Documents/myfile.txt

And that file contains

Text

Some more text

How can I append

Even more text

to the end of that file?

Community
  • 1
  • 1
tobeannounced
  • 1,999
  • 1
  • 20
  • 30
  • Do you want to append text to that file programatically or manually? programatically: do it like any other app does: http://stackoverflow.com/questions/4779877/how-to-write-in-append-mode-for-text-file manually: use any TextEditor in your iPhone you want – thomas Jun 21 '11 at 09:32
  • @Younes Jailbreaking is legal in US and most (all?) countries. See http://www.wired.com/threatlevel/2010/07/feds-ok-iphone-jailbreaking/ I removed the jailbreaking tag because it is unrelated to the question. I also voted to close because it is duplicate of the question linked by thomas. – Jano Jun 21 '11 at 09:42

1 Answers1

1

Read the content of the file in NSMutableData. convert the appended text to bytes and append the bytes to NSMutableData then write the NSMutableData to File

Basbous
  • 3,927
  • 4
  • 34
  • 62
  • 2
    this is working but not elegant for large files because you load the hole file into memory which is not the case in the solution I postet in my comment on the question. direct-link: http://stackoverflow.com/questions/4779877/how-to-write-in-append-mode-for-text-file – thomas Jun 21 '11 at 15:23