开发者

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 co开发者_开发知识库de

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...........


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");


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜