iOS开发代码:从文本文件中读取内容到字符串里
2013-11-17 10:22
357 查看
NSError *error;
NSString *textFileContents = [NSString
stringWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@”myTextFile”
ofType:@”txt”]
encoding:NSUTF8StringEncoding
error: & error];
// If there are no results, something went wrong
if (textFileContents == nil) {
// an error occurred
NSLog(@”Error reading text file. %@”, [error localizedFailureReason]);
}
NSArray *lines = [textFileContents componentsSeparatedByString:@” ”];
NSLog(@”Number of lines in the file:%d”, [lines count] );
NSString *textFileContents = [NSString
stringWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@”myTextFile”
ofType:@”txt”]
encoding:NSUTF8StringEncoding
error: & error];
// If there are no results, something went wrong
if (textFileContents == nil) {
// an error occurred
NSLog(@”Error reading text file. %@”, [error localizedFailureReason]);
}
NSArray *lines = [textFileContents componentsSeparatedByString:@” ”];
NSLog(@”Number of lines in the file:%d”, [lines count] );
相关文章推荐
- iOS开发代码:从文本文件中读取内容到字符串里(+ .json文件)
- iOS学习笔记21—从文本文件中读取内容到字符串里
- 小白学开发(iOS)OC_ 从文件中读取字符串内容(201 4000 5-08-14)
- Hpple-iOS解析HTML-hpple读取html文件内容的代码 更新了下拉刷新功能
- iOS开发之一些字符串常用的代码
- iOS开发之一些字符串常用的代码
- iOS开发之一些字符串常用的代码
- C++代码一次读取文本文件全部内容到string对象
- iOS开发之时间戳(或date)转字符串的实例代码
- iOS开发之一些字符串常用的代码
- AB程序核心代码(MFC从文件读取一行+MFC字符串处理+C在文件末尾追加内容)
- IOS/Android开发用递归法获取指定开始字符串到结尾字符串中间内容
- C语言读取文本文件字符串内容不对,可能是文本编码问题
- iOS开发之一些字符串常用的代码
- iOS开发ASIHTTPRequest直接读取磁盘数据流的请求体的内容
- 使用Apache commons的FileUtils类读取文本文件内容到字符串
- iOS开发之一些字符串常用的代码
- C++代码一次读取文本文件全部内容到string对象
- 代码回顾:从一个文本文件中读取一行的内容,进行数据处理。
- 【iOS开发-64】微博案例练习:用代码自定义cell,主要内容是针对不同高度的cell