我正在尝试在iPhone上下载一个大文件,并在下载时将其保存到磁盘.
理想情况下,在:
-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {
}
Run Code Online (Sandbox Code Playgroud)
我想将'data'附加到磁盘上的文件中.
我查看了NSData文档.有一些函数可以写入文件,但我看不到要附加到现有文件的任何内容.
有谁知道如何追加这些数据?任何帮助非常感谢!缺口.
我有一些来自Tuaw的示例代码,可能是3个版本旧;)编译器发出警告,该方法已被弃用,但我没有看到SDK文档中提到的.如果不推荐使用,则必须采用替代方法或替代方法.有谁知道这种方法的替代品是什么?
具体代码是:
NSArray *crayons = [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt"]] componentsSeparatedByString:@"\n"];
Run Code Online (Sandbox Code Playgroud)
修改后的代码(在离散的白痴步骤中 - 没有错误处理)是:
NSError *error;
NSString *qs = [[NSBundle mainBundle] pathForResource: @"crayons" ofType: @"txt"];
NSString *ps = [[NSString alloc] stringWithContentsOfFile:qs encoding:NSUTF8StringEncoding error: &error];
NSArray *crayons = [[NSArray alloc] arrayWithContentsOfFile: ps];
Run Code Online (Sandbox Code Playgroud)