IOS-Plist文件存储(1)
2014-07-09 00:08
239 查看
1.什么是文件系统?
IOS中每个应用都有自己的文件系统,并有相应的访问权限,一般分为
~/Documents/
~/tmp/
~/Library/Caches/
~/Library/Preferences/-------键值对,不用关心文件路径。
其路径的获取方式为
Plist文件只能存储NSString NSNumber NSData NSArray NSDictionary的内容,其文件存储为xml格式
NSArray存储到Documents中:
NSDictionary存储到Cache中:
NSData读取图片:
IOS中每个应用都有自己的文件系统,并有相应的访问权限,一般分为
~/Documents/
~/tmp/
~/Library/Caches/
~/Library/Preferences/-------键值对,不用关心文件路径。
其路径的获取方式为
<span style="color:#999999;">{ //获取主目录 NSString *path=NSHomeDirectory(); NSString *docPath=[path stringByAppendingPathComponent:@"Documents"]; NSLog(@"%@",docPath); //获取文件目录 NSArray *DocumentPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSAllDomainsMask, YES); // NSLog(@"%@",DocumentPath[0]); //获取缓存目录 NSArray *cachePath=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSAllDomainsMask, YES); // NSLog(@"%@",cachePath[0]); //获取临时目录 NSString *temp=NSTemporaryDirectory(); // NSLog(@"%@",temp); }</span>
Plist文件只能存储NSString NSNumber NSData NSArray NSDictionary的内容,其文件存储为xml格式
NSArray存储到Documents中:
NSArray *arr=@[@"name",@"age",@"height"]; NSString *path=NSHomeDirectory(); NSString *docPath=[path stringByAppendingPathComponent:@"Documents"]; NSString *filepath=[docPath stringByAppendingPathComponent:@"/aa.plist"]; //把array存储到plist文件中 [arr writeToFile:filepath atomically:YES]; //从文件路径读取为array NSArray *arr2=[NSArray arrayWithContentsOfFile:filepath];
NSDictionary存储到Cache中:
NSDictionary *dic=@{@"name":@"lean",@"age":@24,@"height":@172 }; NSArray *dicArr=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSAllDomainsMask, YES); NSLog(@"%@",dicArr[0]); NSString *dirPath=dicArr[0]; NSString *filePath=[dirPath stringByAppendingPathComponent:@"dic.plist"]; //把Dictionary存储到plist文件中 [dic writeToFile:filePath atomically:YES]; //从文件路径读取为Dictionary NSDictionary *dic2=[NSDictionary dictionaryWithContentsOfFile:filePath ];
NSData读取图片:
//读写图片吧能直接存储 只能通过NSData来存储。 //以下例子为从UIImageView中存储文件并在另一个控件中读取显示 NSArray *arr=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSAllDomainsMask, YES); NSLog(@"%@",arr[0]); NSString *cachePath=arr[0]; NSString *filePath=[cachePath stringByAppendingPathComponent:@"image.plist"]; UIImage *image=[self.a image]; NSData *data=UIImageJPEGRepresentation(image,1); [data writeToFile:filePath atomically:YES]; NSData *data2=[NSData dataWithContentsOfFile:filePath]; UIImage *image2=[UIImage imageWithData:data2 ]; self.b.image=image2;
相关文章推荐
- IOS开发之JSON转PLIST(把存储json格式的文件转换成plist文件)
- IOS-Plist文件存储(1)
- iOS应用程序安全(20)-本地数据存储及其安全性(NSUserDefaults, CoreData, Sqlite, Plist 文件)
- iOS开发之JSON转PLIST(把存储json格式的文件转换成plist文件)
- iOS应用程序安全(20)-本地数据存储及其安全性(NSUserDefaults, CoreData, Sqlite, Plist 文件)(转)
- iOS 数据存储 plist文件存储
- ios plist文件存储数据
- IOS学习 沙盒位置,沙盒存储的三种方式:plist文件,偏好设置,归档
- iOS开发的一些小技术:让UIImage有缩放功能、控制log的输出、xcode修改文件注释、随机数的使用、在UIImageView 中旋转图像、在Quartz中如何设置旋转点、创建.plist文件并存储
- IOS 获得项目中info.plist文件的内容 2.沙盒的数据存储及读取 3.控制器view的高度和状态栏statusBar
- iOS应用中存储用户设置的plist文件的创建与读写教程
- iOS 读写plist文件(Date的存储有些怪异,原因不详)
- iOS本地存储 plist文件和归档
- ios学习之plist文件的读写以及存储位置的探究
- iOS应用程序安全(20)-本地数据存储及其安全性(NSUserDefaults, Keychain,CoreData, Sqlite, Plist 文件)
- iOS开发:数据存储之plist文件操作
- iOS应用程序安全(20)-本地数据存储及其安全性(NSUserDefaults, CoreData, Sqlite, Plist 文件)
- iOS-数据持久化存储(plist文件和writeToFile的使用)
- iOS应用程序安全(20)-本地数据存储及其安全性(NSUserDefaults, CoreData, Sqlite, Plist 文件)
- iOS-数据存储方式一之plist文件存储