首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

ios资料读写

2013-08-13 
ios文件读写//写入缓存文件,缓存目录下NSArray *paths NSSearchPathForDirectoriesInDomains(NSDocument

ios文件读写

//写入缓存文件,缓存目录下    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);    NSString *strDocumentsDirectory = paths[0];    NSString *strCacheDirectoryName = [strDocumentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_Alarm",@"2000000022"]];        NSString *strURL = @"http://farm8.static.flickr.com/7443/9493141210_bfda8b9572_s.jpg";    NSError *error = nil;    NSData *dataImg = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL] options:NSDataReadingMappedIfSafe error:&error];    if ([error code] == 0)    {        if([[NSFileManager defaultManager] fileExistsAtPath:strCacheDirectoryName])        {            NSLog(@"文件夹存在");        //创建文件夹路径        [[NSFileManager defaultManager] createDirectoryAtPath:strCacheDirectoryName withIntermediateDirectories:YES attributes:nil error:nil];                NSString *imagePath =[strCacheDirectoryName stringByAppendingPathComponent:@"2000000022_01.jpg"];        //图片写入文件夹        [UIImagePNGRepresentation([UIImage imageWithData:dataImg]) writeToFile:imagePath atomically:YES];        }        else        {            NSLog(@"不存在该文件夹");        }    }

热点排行