iOS plist 文件读写操作

1丶 读

  //创建文件管理器

    NSFileManager *fileManager = [NSFileManager  defaultManager];

    

    NSArray *pathA = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

    

    NSString *documentation = [pathA   objectAtIndex:0];

    //更改到待操作的目录下

    [fileManager changeCurrentDirectoryPath:[documentation stringByExpandingTildeInPath]];

    

    NSString *path = [documentation   stringByAppendingPathComponent:@"citys.plist"];

  //读取的数组

   NSArray * array=[[NSArray alloc] initWithContentsOfFile:path];

2丶写

 //获取路径对象

    

 

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

    

    //获取完整路径

    

    NSString *documentsDirectory = [paths objectAtIndex:0];

    

    NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@"citys.plist"];

//DataArray 就是写入的数组


[DataArray writeToFile:plistPath atomically:YES];




你可能感兴趣的:(iOS plist 文件读写操作)