沙盒路径与文件写入

//获取沙盒根目录
NSString *directory = NSHomeDirectory();
NSLog(@"directory:%@", directory);
//获取Documents路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
NSLog(@"path:%@", path);
//获取Library路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
NSLog(@"path:%@", path);
//获取Caches路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
NSLog(@"path:%@", path);
NSString *tmp = NSTemporaryDirectory();
NSLog(@"tmp:%@", tmp);
UIImage *image = [UIImage imageNamed:@"flower.png"]; NSString *path_sandox = NSHomeDirectory();
//设置一个图片的存储路径
NSString *imagePath = [path_sandox stringByAppendingString:@"/Documents/flower.png"];
//把图片直接保存到指定的路径(同时应该把图片的路径imagePath存起来,下次就可以直接用来取)
[UIImagePNGRepresentation(image)  writeToFile:imagePath atomically:YES];

你可能感兴趣的:(沙盒路径与文件写入)