tags:

views:

32

answers:

2

How to retrieve the contents of a TEXT FILE stored locally in the documents directory?

+1  A: 

Assuming the text is UTF-8 encoded:

NSData *textFileData = [NSData dataWithContentsOfFile:pathToTextFile];
NSString *textFileString = [NSString stringWithUTF8String:[textFileData bytes]];
Alex Reynolds
+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