How to retrieve the contents of a TEXT FILE stored locally in the documents directory?
views:
32answers:
2
Q:
How to get the contents of a text file (stored locally in the documents directory) into an NSString?
+1
A:
Assuming the text is UTF-8 encoded:
NSData *textFileData = [NSData dataWithContentsOfFile:pathToTextFile];
NSString *textFileString = [NSString stringWithUTF8String:[textFileData bytes]];
Alex Reynolds
2010-01-31 10:57:26
+1
A:
You can also use this NSString
class method (assuming the text is UTF-8):
NSString *content = [NSString stringWithContentsOfFile:pathToTextFile encoding:NSUTF8StringEncoding error:&error];
error
should be a pointer to an NSError
object.
Justin Voss
2010-02-01 00:13:12