Plist 数据库的使用方法
2015-11-11 22:07
330 查看
plist一,简单介绍一下常用的plist文件。全名是:Property List,属性列表文件,它是一种用来存储串行化后的对象的文件。属性列表文件的扩展名为.plist ,因此通常被称为 plist文件。文件是xml格式的。 Plist文件通常用于储存用户设置,也可以用于存储捆绑的信息 。NSUserDefault 轻量级数据持久化工具 NSUserDefault本质是一个本地的plist文件。只能接收基础数据类型的数据进行存储二,先说文件保存到的几个位置:1,工程沙盒里(就是程序user Document文件夹下,以读取文件,写入文件方式)2,工程自身里(就是在工程里手动创建一个如.plist文件,把固定的内容写入,这个需要人工手动写入)3,工程沙盒里(保存到user Document下,不过不需要读写文件,用系统的 NSUserDefaults 可以快速保存添加读取删除基本数据类型,类似于android里的Sharedpreferences )先封装一个 类//获取 一个文件 在沙盒Library/Caches/ 目录下的路径+ (NSString *)getFullPathWithFile:(NSString *)urlName {//先获取 沙盒中的Library/Caches/路径NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];NSString *myCacheDirectory = [docPath stringByAppendingPathComponent:@"MyCaches"];//检测MyCaches 文件夹是否存在if (![[NSFileManager defaultManager] fileExistsAtPath:myCacheDirectory]) {//不存在 那么创建[[NSFileManager defaultManager] createDirectoryAtPath:myCacheDirectory withIntermediateDirectories:YES attributes:nil error:nil];}////用md5进行 加密 转化为 一串十六进制数字 (md5加密可以把一个字符串转化为一串唯一的用十六进制表示的串)NSString * newName = [urlName MD5Hash];//拼接路径return [myCacheDirectory stringByAppendingPathComponent:newName];}//导入头文件#import <CommonCrypto/CommonDigest.h>- (NSString *)MD5Hash{const char *cStr = [self UTF8String];unsigned char result[16];CC_MD5(cStr, strlen(cStr), result);return [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",result[0], result[1], result[2], result[3],result[4], result[5], result[6], result[7],result[8], result[9], result[10], result[11],result[12], result[13], result[14], result[15]];}NSString *path = [self getFullPathWithFile:url];//读本地NSData *data = [NSData dataWithContentsOfFile:path];//写本地[data writeToFile:path atomically:YES];//图片写入本地沙河的方法[UIImageJPEGRepresentation(imagV.image, 1) writeToFile:path atomically:YES];/由于图片存入的是时候使用加密的方式 因此取出的时候要//取得一个目录下得所有文件名NSArray *filesArr = [[NSFileManager defaultManager] subpathsAtPath: myCacheDirectory];NSLog(@"%lu",(unsigned long)filesArr.count);for (NSInteger i = 0; i<filesArr.count; i++) {NSString *filePath = [myCacheDirectory stringByAppendingPathComponent:filesArr[i]];UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfFile:filePath]];// NSData *data = [NSData dataWithContentsOfFile:arr[i]];//UIImage *imag = [UIImage imageWithData:data];[self.dataArr addObject:image];}
相关文章推荐
- MySQL 5.7 zip版 安装过程
- Oracle 删除重复数据只留一条
- Mysql千万级别数据优化方案(单表)
- TimesTen 模拟锁表操作
- oracle rac查看磁盘组使用情况
- MySQL文件位置管理
- 基本开题的感觉是了-MySQL继续继续(自定义函数&存储过程)
- BigInsights -- 基于 Hadoop 的数据分析平台【基于db2数据库】
- mac中使用redis cluster 配置出现的问题
- sqlserver2008r2实现镜像
- sqlserver2008r2实现镜像
- mysql之触发器的使用
- 使用redis-cli定时执行指定命令
- 数据库表与表连接的方式(内连接、外连接[左连接、右连接、全连接]、交叉连接)
- iOS数据库操作(使用FMDB)
- oracle 11G 实验 in 和 exists 区别
- 使用MySql自带的库进行数据库连接时可能产生的一些问题
- ASP.NET Redis 开发
- 在文件地理数据库中使用 SQL 进行报告和分析
- 【SDCC讲师专访】腾讯潘安群:腾讯云金融级数据库TDSQL分析