zoukankan      html  css  js  c++  java
  • NSArry 存储本地;&&读取本地文件

     //如果指定的路径下面没有文件,系统hi创建一个文件,如果有,删除; 重新添加
                NSFileManager *filemanager = [NSFileManager defaultManager];
                if ([filemanager fileExistsAtPath:[self filePath]]) {
                    
                    NSError *err;
                    [filemanager removeItemAtPath:[self filePath] error:&err];
                }
                
                NSData *data_ = [NSKeyedArchiver archivedDataWithRootObject:imagearr];
                [filemanager createFileAtPath:[self filePath] contents:data_ attributes:NULL];
    
    //读取NSSArry
     NSFileManager *f = [NSFileManager defaultManager];//NSFileManager 对目录进行管理,对文件进行管理
        
        if ([f fileExistsAtPath:[self filePath]]) {
            NSData *data_ = [NSData dataWithContentsOfFile:[self filePath]];
            //NSMutableArray *arr = [NSMutableArray arrayWithContentsOfFile:[self filePath]];
            NSMutableArray *arr = [NSKeyedUnarchiver unarchiveObjectWithData:data_];
           
    
        }
        
    
    
    
    
    //文件路径
    - (NSString *)filePath
    {
        //document路径
        NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        //具体文件路径
        NSString *path = [docPath stringByAppendingPathComponent:@"Myimages"];//zifu字符串拼接
        
        return path;
    }
    
  • 相关阅读:
    es6 yield简单使用
    es6 generator 函数中的yield理解
    es6 promise的使用,同时处理多个异步请求
    es6 filter的使用
    ES6中reduce的计算过程
    es6函数的参数展开
    搭建基于express框架的运行环境
    通过node.js搭建服务,访问html静态页面
    docker compose
    JDBCUtil
  • 原文地址:https://www.cnblogs.com/KingQiangzi/p/3555634.html
Copyright © 2011-2022 走看看