您的位置:首页 > 移动开发 > IOS开发

iOS plist文件创建于读取

2014-10-16 14:31 197 查看
plist 文件读写
//1. 创建一个plist文件
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); www.2cto.com
NSString *path=[paths objectAtIndex:0];
NSLog(@"path = %@",path);
NSString *filename=[path stringByAppendingPathComponent:@"test.plist"];
NSFileManager* fm = [NSFileManager defaultManager];
[fm createFileAtPath:filename contents:nil attributes:nil];
//NSDictionary* dic = [NSDictionary dictionaryWithContentsOfFile:plistPath];

//创建一个dic,写到plist文件里
NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:@"sina",@"1",@"163",@"2",nil];
[dic writeToFile:filename atomically:YES];

//读文件
NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];
NSLog(@"dic is:%@",dic2);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: