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 中的文件
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
