Append NSData to a file in Objective C(将 NSData 附加到 Objective 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 附加到 Objective C 中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 NSData 附加到 Objective C 中的文件


- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01