Iphone 数据长度为零?错误:Cocoa错误60

Iphone 数据长度为零?错误:Cocoa错误60,iphone,objective-c,xcode,nsdata,Iphone,Objective C,Xcode,Nsdata,日志值:长度:0错误:操作无法完成。 (错误60) 数据正确地保存在文件路径上,但从同一路径获取数据时,数据为零 提前感谢。问题是您没有写入可写文件路径。这很可能是因为您正在转义文件路径,这是不必要的,事实上,如果转义路径不存在,可能会导致IO读/写失败。转义百分比应仅用于HTTP请求或相关NSURL操作。尝试删除该行: NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUser

日志值:长度:0错误:操作无法完成。 (错误60)

数据正确地保存在文件路径上,但从同一路径获取数据时,数据为零


提前感谢。

问题是您没有写入可写文件路径。这很可能是因为您正在转义文件路径,这是不必要的,事实上,如果转义路径不存在,可能会导致IO读/写失败。转义百分比应仅用于HTTP请求或相关NSURL操作。尝试删除该行:

NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,   NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:currentVideoDownload];

filePath = [filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[responseData writeToFile:filePath atomically:YES];

NSError *error;

NSData *mediaData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMapped   error:&error];

NSLog(@"Length:%d Error:%@",[mediaData length],[error localizedDescription]);

如果不检查
-writeToFile:atomically:
的返回值,您如何知道数据已正确保存?另外,是否确实要通过在文件路径上附加百分比转义usingencode:来使用
-string?也许
-stringByExpandingTildeInPath:
更合适。。。您还可以尝试记录
错误。userInfo
以获取有关读取操作失败原因的详细信息。@MichaelDautermann…谢谢。。responseData是来自方法ConnectionIDFinishLoading:中的服务器…的数据。我正在模拟器上测试…响应数据成功写入路径,即filePath。当我转到该路径时,我可以手动播放该文件。但是当我使用相同的文件路径来获取NSData时,它是零。@MarkAdams…谢谢…我使用了error.userInfo…获取这个:error:{NSFilePath=“/Users/Altu/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/75D3B5E2-C6BD-46B3-8F61-1FAC3D291070/Documents/test.mp4”;NSUnderlyingError=“Error Domain=NSPOSIXErrorDomain Code=2\”操作无法完成。没有这样的文件或目录“”
filePath = [filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];