Questions tagged «nsstream»

18
Objective-C:逐行读取文件
在Objective-C中处理大型文本文件的适当方法是什么?假设我需要分别阅读每一行,并希望将每一行都视为NSString。最有效的方法是什么? 一种解决方案是使用NSString方法: + (id)stringWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError **)error 然后使用换行符分隔线,然后遍历数组中的元素。但是,这似乎效率很低。没有简单的方法将文件视为流,枚举每一行,而不是一次全部读取吗?有点像Java的java.io.BufferedReader。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.