在iphone中保存数据

时间:2011-02-14 08:59:35

标签: iphone cocoa-touch

我正在尝试从网址下载图像和音频文件..我想将下载的文件保存在特定路径中是​​否可能..

请建议我......

谢谢......

2 个答案:

答案 0 :(得分:3)

将文件保存在应用的文档目录中。

NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *path = [documentsDirectoryPath stringByAppendingPathComponent:@"myfile.mp3"];
BOOL success = [myMp3Data writeToFile:path atomically:YES];

答案 1 :(得分:1)

是的,有可能。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *filePath2 = [NSString stringWithFormat:@"%@/%@.jpg", documentsDirectory, fileName]; 
NSData* imageData = UIImageJPEGRepresentation(drawImage.image, 1.0); 
[imageData writeToFile:filePath2 atomically:NO];