plist文件的读取 写入

手动创建的plist文件只能手动写入,代码写入的放在沙盒中

NSString*pathP = [[NSBundlemainBundle]pathForResource:@"University List"ofType:@"plist"];

NSMutableArray*arrP = [NSMutableArrayarrayWithContentsOfFile:pathP];

NSString*path = [[NSBundlemainBundle]pathForResource:@"xg"ofType:@"txt"];

NSString*str = [NSStringstringWithContentsOfFile:pathencoding:NSUTF8StringEncodingerror:nil];

NSArray*arr = [strcomponentsSeparatedByString:@"\n"];

for(inti=0; icount; i++) {

NSDictionary*tmp = [NSDictionarydictionaryWithObject:arr[i]forKey:[NSStringstringWithFormat:@"U%d",i+1]];

[arrPaddObject:tmp];

}

// SKLog(@"arrP:%@",arrP);

//获取应用程序沙盒的Documents目录

NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);\

NSString*plistPath1 = [pathsobjectAtIndex:0];

SKLog(@"paths:%@",plistPath1);

//得到完整的文件名

NSString*filename=[plistPath1stringByAppendingPathComponent:@"University List.plist"];

[arrPwriteToFile:filenameatomically:YES];

NSMutableArray*data1 = [[NSMutableArrayalloc]initWithContentsOfFile:filename];

SKLog(@"data1:%@",data1);

你可能感兴趣的:(plist文件的读取 写入)