How can I read a .txt file inside documents directory? Can you show me code?
2 Answers
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]; 1 Comment
Allison
As simple and easy as the snippet is, I would recommend adding some context or code comments
You can also use NSFileHandle for writing data in file and save to document directory: You can follow: NSFileHandle