我已使用此代码将字符串写入同一个文件 10 次。但它会覆盖每次新发布的先前数据。我想将新数据附加到旧数据。
[@"one" writeToFile:[self returnDocumentsDirectory] atomically:NO encoding:NSASCIIStringEncoding error:nil];
-(NSString *)returnDocumentsDirectory
{
NSArray *DocumentsDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [DocumentsDirectoryPath objectAtIndex:0];
NSString *filePath = [path stringByAppendingPathComponent:@"History.txt"];
return filePath;
}