-(void)writeToFile:(NSData *)data
{
NSString *filePath=[NSString stringWithFormat:@"%@",_fileName];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath] == NO)
    {
[[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
}
FILE *file = fopen([_fileName UTF8String], [@"ab+" UTF8String]);
if(file != NULL)
    {
fseek(file, 0, SEEK_END);
        int readSize = [data length];
        fwrite((const void *)[data bytes], readSize, 1, file);
        fclose(file);
}
    else
    {
        NSLog(@"open %@ error!", _fileName);
    }
}这是直接写文件的一种方式,其他逻辑自己处理下。