tags:

views:

576

answers:

1

In Cocoa, how can I write a string to a text file without replacing the contents of the file, like writing at the end of the file?

For example the following code:

BOOL written = [data writeToFile:[path stringByAppendingPathComponent:@"conf.txt"] options:NSAtomicWrite error:&error];

The data (string) was written to the text file however it replaced the original contents of the file.

Any suggestions?

+4  A: 

First call this method to seek to the end of the file.

Then use this method (instead of writeToFile) to append your data to the end of the file.

colithium