NSFileManager * fileManager = nil;
NSArray *paths = nil;
NSString *documentsDirectory = nil;
NSString * folerName = @"Photos";
NSString * fileName = @"myphoto.png";
NSString * filePath = nil;
UIImage *photoimage = nil;
NSData * imageData = nil;
//Documents:
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//Caches:
paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
documentsDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:folerName];
fileManager = [[NSFileManager alloc]init];
[fileManager createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:error];
2、创建目录并在目录中存储对象createFileAtPath: contents: attributes
filePath = [documentsDirectory stringByAppendingPathComponent:filename];
if((![fileManager fileExistsAtPath: fullPathToFile]))
{
photoimage = [[UIImage alloc] imageNamed:@"photo.png"];
imageData = UIImagePNGRepresentation(photoimage);
[fileManager createFileAtPath:filePath contents: imageData attributes:nil];
}
[fileManager release];
3、删除目录中指定文件
NSString * filePath = [documentsDirectory stringByAppendingPathComponent: fileName];