![](/img/trans.png)
[英]iPhone: How to get the contents of the documents directory as a NSMutableArray?
[英]How to get the contents of a text file (stored locally in the documents directory) into an NSString?
如何检索本地存储在documents目录中的TEXT FILE的内容?
假设文本是UTF-8编码的:
NSData *textFileData = [NSData dataWithContentsOfFile:pathToTextFile];
NSString *textFileString = [NSString stringWithUTF8String:[textFileData bytes]];
您还可以使用此NSString
类方法(假设文本为UTF-8):
NSString *content = [NSString stringWithContentsOfFile:pathToTextFile encoding:NSUTF8StringEncoding error:&error];
error
应该是指向NSError
对象的指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.