【发布时间】:2011-03-03 11:14:17
【问题描述】:
我正在使用 NSURLConnection 从服务器下载文件并将其存储在本地,如下所示
-(void) connection:(NSURLConnection *)connection
didReceiveData:(NSData *)data
{
[webData appendData:data];
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
self.documentsDir = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"NewResult.zip" ];
[[NSFileManager defaultManager] createFileAtPath:documentsDir contents:nil attributes:nil];
NSFileHandle *file1 = [NSFileHandle fileHandleForUpdatingAtPath: documentsDir];
[file1 writeData: webData];
[file1 closeFile];
}
这是有效的,但每次都会覆盖旧文件 如何避免这种过度写入我知道使用 NSURLDownload 可以做到这一点,但这里我没有使用 NSURLDownload。
【问题讨论】:
标签: iphone objective-c file nsurlconnection