//写入缓存文件,缓存目录下
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(@"不存在该文件夹");
}
}