Read a .txt file inside documents directory

cyclingIsBetter picture cyclingIsBetter · Jul 1, 2011 · Viewed 12.5k times · Source

How can I read a .txt file inside documents directory? Can you show me code?

Answer

taskinoor picture taskinoor · Jul 1, 2011
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"txtFile.txt"];
NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];