Possible Duplicate:
How to append string in local resource txt file for iOS sdk
My code goes like this:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
docFile_V1 = [docDir stringByAppendingPathComponent:LOG_FILE_V1];
if ([file fileExistsAtPath: docFile_V1] == YES)
{
if(![formatedlogStr writeToFile:docFile_V1 atomically:YES encoding:NSUTF8StringEncoding error:&error])
{
NSLog(@"Error: %@", [error userInfo]);
}
}
This is my code for writing into the file, but unfortunately it overwrites all the previous contents of the file. I want to write a string without overwriting the previous one.
Can anybody suggest the best way to write or append to the file by example?
Firstly, you should read the contents of the file in a NSMutableArray, then append your data to your array, and write it to the file again.