iOS文件操作

时间:2023-03-09 20:34:56
iOS文件操作
  //找到Documents文件所在的路径
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    //取得第一个Documents文件夹的路径
    
    NSString *filePath = [path objectAtIndex:];
    
   
    
    NSString *plistPath = [filePath stringByAppendingPathComponent:@"collectionData.plist"];     //存入(沙盒)
    [data writeToFile:plistPath atomically:YES];
    //读取(沙盒)
    NSArray *arr1 = [NSArray arrayWithContentsOfFile:plistPath];
     NSLog(@"%@",plistPath);
    NSLog(@"%@",arr1);
    
    NSString *bundlePath = [[NSBundle mainBundle]pathForResource:@"collectionData" ofType:@"plist"];
    NSLog(@"%@",bundlePath);
    //读取(Bundle)
    NSArray *arr2 = [NSArray arrayWithContentsOfFile:bundlePath];
    NSLog(@"---------%ld",arr2.count);