I am looking to create a text file on my iPhone programmatically and also write some data onto the file. How can I read the text file manually?
Asked
Active
Viewed 2,219 times
2
-
possible duplicate of [create text file & save](http://stackoverflow.com/questions/6123284/create-text-file-save) – jscs Aug 28 '11 at 18:58
1 Answers
2
Use NSString
's initWithContentsOfFile:encoding:error:
to read the file, then use stringByAppendingFormat:
to add some data, and then use writeToFile:atomically:encoding:error:
to write it on disk.

gcamp
- 14,622
- 4
- 54
- 85
-
hi thanks i was checking through this, but where can i find the file on my iPhone?? – Suppi Aug 28 '11 at 14:14
-
In the user's Document directory : http://stackoverflow.com/questions/272544/whats-the-best-way-to-find-the-users-documents-directory-on-an-iphone – gcamp Aug 28 '11 at 14:17
-
i mean can i view the file manually. And where is this Document directory located?? – Suppi Aug 28 '11 at 14:18
-
No you can't view the file manually on a device. You need to access it programatically. – gcamp Aug 28 '11 at 14:22
-
I am actually writing an application, where i need to write some data to a log file in the form of a .txt or .gpx file. So later the user can read the file manually or use it basically. Do you know of anyway i could do this?? – Suppi Aug 28 '11 at 14:47
-
Add it in you app's bundle and read it from there. You'll need to write in the document directory since writing from your bundle is not possible. – gcamp Aug 28 '11 at 14:51
-
hi i am sorry for asking too many q, i am trying to understand somethings, could you please tell me how i could add it in the app's bundle and read it ?? – Suppi Aug 28 '11 at 15:05
-
Hi nevermind, i found an iPhone Explorer to get the .txt file from the Documents directory.. Thanks for your support – Suppi Aug 28 '11 at 15:39