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;
    }
    
  • 相关阅读:
    form表单
    JsonResponse对象
    HttpRequest对象
    Django基础
    ssh私钥登录
    监控window目录是否为空自定义item
    redis频繁报错Cannot allocate memory
    脱敏html文件文件
    MySQL删除数据
    ftp服务器搭建
  • 原文地址:https://www.cnblogs.com/KingQiangzi/p/3555634.html
Copyright © 2011-2022 走看看