将 NSData 附加到 Objective C 中的文件
我正在尝试在 iPhone 上下载一个大文件,并在下载时将其保存到磁盘。
理想情况下,在:
-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {
}
我想将“数据”附加到磁盘上的文件中。
我已经查看了 NSData 文档。 有可以写入文件的函数,但我看不到任何可以附加到现有文件的内容。
有谁知道我如何附加这些数据? 非常感谢任何帮助! 缺口。
I'm attempting to download a large file on the iPhone and save it to disk as it is downloaded.
Ideally, in:
-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {
}
I want to append 'data' to a file on disk.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以结合使用
NSFileHandle
类中的-writeData:
和-seekToEndOfFile
方法将NSData
写入末尾一个文件的。You can use a combination of
-writeData:
and-seekToEndOfFile
methods fromNSFileHandle
class for writingNSData
to the end of a file.有一个 Apple 示例应用程序下载到文件,使用 NSOutputStream 写入文件。 查看名为“SimpleURLConnections”的示例应用程序的文件“GetController.h”。
这是一个直接的 URL——尽管我认为如果您没有登录到developer.apple.com,它就不会起作用。
https:// developer.apple.com/library/ios/#samplecode/SimpleURLConnections/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009245
There's a Apple sample app that downloads to a file, using NSOutputStream to write to the file. Look in file "GetController.h" of the sample app called "SimpleURLConnections".
Here's a direct URL -- although I don't think it'll work if you're not logged into to developer.apple.com.
https://developer.apple.com/library/ios/#samplecode/SimpleURLConnections/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009245