1.文件的复制
NSFileManager * manager =[NSFileManager defaultManager];
//获取资源文件的路径
NSString * filePath =[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"hangC.plist"];
//本地沙箱路径
NSString * documentDic =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
NSString * path =[documentDic stringByAppendingPathComponent:@"hangC.plist"]
//拷贝
[manager copyItemAtPath:filePath toPath:path error:nil];
2.修改plist文件,将一个新元素“zhangchi”加了进去
NSString * documentDic =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
NSString * path =[documentDic stringByAppendingPathComponent:@"hangC.plist"];
NSString * new =@"zhangchi";
NSMutableArray * array =[NSMutableArray arrayWithContentsOfFile:path];
[array addObject:new];
[array writeToFile:path atomically:YES];
3.writeToFile相当于清空然后重新写入,执行下面代码后,plist文件中只存在“皮卡丘”
NSMutableArray * array2 =[NSMutableArray arrayWithObject:@"皮卡丘"];
[array2 writeToFile:path atomically:YES];
4.沙盒存储组成
Documents:用于存储非常大的文件或需要非常频繁更新的数据,能够进行iTunes或iCloud的备份。
Library:Preferences和Caches
Preferences:用于存放应用程序的设置
Caches:用来存放应用程序的数据,存储缓存。
tmp:临时文件目录