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;
    }
    
  • 相关阅读:
    LeetCode 121. Best Time to Buy and Sell Stock
    LeetCode 221. Maximal Square
    LeetCode 152. Maximum Product Subarray
    LeetCode 53. Maximum Subarray
    LeetCode 91. Decode Ways
    LeetCode 64. Minimum Path Sum
    LeetCode 264. Ugly Number II
    LeetCode 263. Ugly Number
    LeetCode 50. Pow(x, n)
    LeetCode 279. Perfect Squares
  • 原文地址:https://www.cnblogs.com/KingQiangzi/p/3555634.html
Copyright © 2011-2022 走看看