开发者

How to View saved files in iphone

开发者 https://www.devze.com 2023-01-19 03:02 出处:网络
Hi i created one sample application that saves data as text file using simple c (FILE) function . I am using below co开发者_开发知识库de

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

精彩评论

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

关注公众号