首页 > 学院 > 开发设计 > 正文

【读书笔记】iOS-读取文本文件

2019-11-14 18:27:31
字体:
来源:转载
供稿:网友

一,文本文件的内容。

 

二,工程目录

 

 

三,ViewController.m

复制代码
- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.    //读取文本文件    [self readFromText];}#PRagma -mark -functions//读取文本文件-(void)readFromText{    NSError *error;    NSString *textFieldContents=[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"chenlihua" ofType:@"txt"] encoding:NSUTF8StringEncoding error:&error];    NSLog(@"--textFieldContents---%@-----",textFieldContents);    if (textFieldContents==nil) {        NSLog(@"---error--%@",[error localizedDescription]);    }    NSArray *lines=[textFieldContents componentsSeparatedByString:@"/n"];    NSLog(@"number of lines in the file:%ld",[lines count]);}
复制代码

 

四,输出如下图所示:

 

复制代码
2015-07-29 22:12:32.692 读取文本文件[1362:70871] --textFieldContents---123456789-----2015-07-29 22:12:32.692 读取文本文件[1362:70871] number of lines in the file:102015-07-29 22:16:09.573 读取文本文件[1362:73057] Terminating since there is no system app.
复制代码

 

参考资料:《iOS数据库应用高级编程(第2版)》


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表