// 在Documents目录下创建一个名为LaunchImage的文件夹
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"LaunchImage"];
NSLog(@"%@",path); NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir = FALSE;
BOOL isDirExist = [fileManager fileExistsAtPath:path isDirectory:&isDir];
if(!(isDirExist && isDir)) {
BOOL bCreateDir = [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
if(!bCreateDir){
NSLog(@"创建文件夹失败!");
}
NSLog(@"创建文件夹成功,文件路径%@",path);
} UIImage *image=[UIImage imageWithContentsOfFile:@"testimage.png"];
NSData *data = UIImagePNGRepresentation(image);
//将testimage.png保存到LaunchImage文件夹下,新名称为image1.png
BOOL isSaved= [fileManager createFileAtPath:[path stringByAppendingString:@"/image1.png"] contents:data attributes:nil];
NSLog(@"图片保存状态:%d",isSaved); //获取保存的图片
UIImage *newimage=[UIImage imageWithContentsOfFile:[path stringByAppendingString:@"/image1.png"]]; // 删除文件
BOOL isDelete=[fileManager removeItemAtPath:path error:nil];
NSLog(@"%d",isDelete);