1.文件内容查看
-(void)loadFile{ NSString *filePath=@"/Users/qing/Library/haha.txt"; if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){ NSData *data=[[NSMutableData alloc]initWithContentsOfFile:filePath]; NSString * str=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"content=%@",str); }else{ NSLog(@"NO"); } }
2.文件存档
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; [archiver encodeObject:fourLines forKey:kDataKey]; [archiver finishEncoding]; [data writeToFile:[self dataFilePath] atomically:YES];
3.获取XML文件
NSString *filePath = [[NSBundle mainBundle] pathForResouse:@"re" ofType:@"xml"]; NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];
获取属性列表
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ViewControllers" ofType:@"plist"]];
4.用户首选项NSuserDefaults
NSUserDefaults *Defaults= [NSUserDefaults standardUserDefaults]; [Defaults setObject:@"helloc ddddyou22" forKey:@"hello"]; //会有缓存数据,要clean NSLog(@"%@",[Defaults objectForKey:@"hello"]);
评论