How can I read a .txt file inside documents directory? Can you show me code?
Asked
Active
Viewed 1.3k times
2 Answers
37
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];

taskinoor
- 45,586
- 12
- 116
- 142
-
1As simple and easy as the snippet is, I would recommend adding some context or code comments – Allison Sep 29 '14 at 02:44
1
You can also use NSFileHandle
for writing data in file and save to document directory:
You can follow: NSFileHandle

Nikhlesh bagdiya
- 21
- 4