[Reading Notes] iOS-reading text files and Reading Notes ios-
1. Content of a text file.
2. project directory
3. ViewController. m
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // read the text file [self readFromText];} # pragma-mark-functions // read the text file-(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]);}
4. The output is shown in:
22:12:32. 692 read a text file [1362: 70871] -- textFieldContents --- 123456789-----2015-07-29 22:12:32. 692 read a text file [1362: 70871] number of lines in the file: 102015-07-29 22:16:09. 573 read the text file [1362: 73057] Terminating since there is no system app.
Reference: iOS database application advanced programming (version 2nd)