Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read a .txt file inside documents directory

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

like image 911
cyclingIsBetter Avatar asked Jul 01 '11 10:07

cyclingIsBetter


People also ask

How do I read a .TXT file?

How to open a TXT file. You can open a TXT file with any text editor and most popular web browsers. In Windows, you can open a TXT file with Microsoft Notepad or Microsoft WordPad, both of which come included with Windows.

How do I open a text file in a directory in Python?

If you want to read a text file in Python, you first have to open it. If the text file and your current file are in the same directory ("folder"), then you can just reference the file name in the open() function.


1 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];
like image 107
taskinoor Avatar answered Sep 28 '22 02:09

taskinoor