将 NSData 附加到目标 C 中的文件 [英] Append NSData to a file in Objective C

查看:31
本文介绍了将 NSData 附加到目标 C 中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 iPhone 上下载一个大文件,并在下载时将其保存到磁盘.

I'm attempting to download a large file on the iPhone and save it to disk as it is downloaded.

理想情况下,在:

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {

}

我想将数据"附加到磁盘上的文件中.

I want to append 'data' to a file on disk.

我已经查看了 NSData 文档.有一些函数可以写入文件,但我看不到任何要附加到现有文件的内容.

I've checked out the NSData documentation. There are functions to write to a file, but I can't see anything to append to an existing file.

有谁知道我如何附加这些数据?非常感谢任何帮助!尼克.

Does anyone know how I can append this data? Any help much appreciated! Nick.

推荐答案

您可以使用 NSFileHandle-writeData:-seekToEndOfFile 方法的组合/code> 类,用于将 NSData 写入文件末尾.

You can use a combination of -writeData: and -seekToEndOfFile methods from NSFileHandle class for writing NSData to the end of a file.

这篇关于将 NSData 附加到目标 C 中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆