Tamil
Tamil

Reputation: 115

How to View saved files in iphone

Hi i created one sample application that saves data as text file using simple c (FILE) function . I am using below code

FILE *fp = fopen("Log.txt", "w");
fprintf(fp,"%s\t %s\t %s\t %s\t %s\t\n","Id","Type","MacId","IPAddress","Version");
fclose(fp);

When i run this code in simulator.There is a Log.txt file in Macintosh HD folder.Then i can able to view the text file log.When i run this in device ,Where it can store .txt file and how can i view this text file ? Is it possible ?

Thanks in advance...........

Upvotes: 0

Views: 1280

Answers (2)

Matthes
Matthes

Reputation: 515

As mentioned by fluchtpunkt, Documents directory is the place where you can put your files. Simplest way to do it is perhaps creating NSString instance and then call writeToFile:atomically:encoding:error: method. Check NSString documentation for details.

Upvotes: 0

Matthias Bauch
Matthias Bauch

Reputation: 90127

save the file to the documents-directory.

NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *fullPath = [docDir stringByAppendingPathComponent:@"Log.txt"];

edit:

FILE *fp = fopen([fullPath cStringUsingEncoding:NSUTF8StringEncoding], "w");

Upvotes: 1

Related Questions