我将文件保存在名为1.png
, 2.png
, 3.png
, 4.png
,的文档目录中5.png
。如果我删除原始文件3.png
,如何重命名文件4.png
并分别5.png
调用3.png
和4.png
?
这是我首先用来编写文件的代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[appDel.photo addObject:@"photo"];
NSString *imageName = [NSString stringWithFormat:@"%i.png", [appDel.photo count]];
appDel.numberPhoto = [appDel.photo count];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
imageName];
NSData* data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];