与您编写的方式相同,您可以检索数据,假设您想从文档文件夹中获取图像,然后查看此代码 -
NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]];
NSString *fileName = [stringPath stringByAppendingFormat:@"/image.jpg"];
//fileName is your image path and image.jpg is your image name which is saved in documents folder...
NSData *retrieveData = [NSData dataWithContentsOfFile:fileName];
UIImage *newImage = [UIImage imageWithData: retrieveData];
在这种情况下,而不是
[data writeToFile:fileName atomically:YES];
你必须写
NSData *retrieveData = [NSData dataWithContentsOfFile:fileName];
线。你可以得到所有类型的数据。
谢谢你!!