首页 > 解决方案 > nsdata 的文件路径

问题描述

我正在尝试从文件路径中获取 NSData,但我不断收到无法打开文件的错误消息。任何想法如何获取路径,以便我可以获取 NSData。

for (int t = 0; t < [self.myarray count]; t++) {
    NSURL *url1 = [NSURL fileURLWithPath:[self.myarray objectAtIndex:t]];
    NSLog (@"url1: %@", url1);
    NSError* error = nil;

    NSString *filePath = [url1 path];
    NSData* data = [NSData dataWithContentsOfFile:filePath options:NSDataReadingUncached error:&error];
    if (error) {
        NSLog(@"Data Error: %@", [error localizedDescription]);

    } else {
        NSLog(@"Data is: %@", data);

    }  

}

这是错误日志

url1:file:///var/mobile/Containers/Data/Application/85E795CA-B31D-4BD7-A777-DE7B392D6762/Documents/pImw.mp4

数据错误:文件“pImw.mp4”无法打开,因为没有这样的文件。

标签: xcode

解决方案


推荐阅读