美文网首页
plist文件的读取 写入

plist文件的读取 写入

作者: 苏渝粤 | 来源:发表于2015-05-29 01:40 被阅读207次

    手动创建的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文件的读取 写入

          本文链接:https://www.haomeiwen.com/subject/rokqqttx.html