一,文本文件的內(nèi)容。

二,工程目錄

三,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數(shù)據(jù)庫應(yīng)用高級(jí)編程(第2版)》
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注