{"id":33,"date":"2008-10-29T18:12:17","date_gmt":"2008-10-29T22:12:17","guid":{"rendered":"httpss:\/\/www.powenko.com\/blog\/?p=33"},"modified":"2009-11-23T11:29:58","modified_gmt":"2009-11-23T15:29:58","slug":"iphonesavefile","status":"publish","type":"post","link":"https:\/\/www.powenko.com\/wordpress\/?p=33","title":{"rendered":"iphone,Save File, Open File in iPhone APP resource folder."},"content":{"rendered":"<p>Below sample code can save a string &#8220;abcdefghijk&#8221;  to Application\/&#8221;1.txt&#8221; file<br \/>\n<code><br \/>\nNSString *str2 = @\"abcdefghijk\";<br \/>\nNSMutableData *dat1 = [[[NSMutableData alloc] autorelease] initWithCapacity:1];<br \/>\n[dat1 appendBytes:[str2 cString] length:[str2 cStringLength]];<br \/>\n[self funFileSave:@\"1.txt\" i_receivedData:dat1];<\/p>\n<p>- (void)funFileSave:(NSString*)i_FileName<br \/>\ni_receivedData:(NSMutableData*) i_receivedDataData<br \/>\n{<br \/>\nNSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:i_FileName];<br \/>\nNSLog(filePath);<br \/>\nNSFileManager *myFile = [ NSFileManager defaultManager];<br \/>\n[myFile createFileAtPath:filePath  contents:i_receivedDataData attributes:nil];<br \/>\n}<\/p>\n<p><\/code><br \/>\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br \/>\nBelow sample code can laod a string from Application\/&#8221;1.txt&#8221; file<\/p>\n<p><code> <\/code><\/p>\n<p><code>NSString* t_FileData=[self funFileLoad:@\"1.txt\"];<\/p>\n<p>- (NSString* )funFileLoad:(NSString*)i_FileName<\/p>\n<p>{<br \/>\nNSString *outData=\"\";<br \/>\nNSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:i_FileName];<br \/>\nNSLog(filePath);<br \/>\nNSFileManager *fm = [NSFileManager defaultManager];<br \/>\nBOOL success = [fm fileExistsAtPath:filePath];<br \/>\nif (success==YES)<br \/>\n{<br \/>\noutData = [NSString stringWithContentsOfFile:filePath];<br \/>\nNSLog(outData);<br \/>\n}<br \/>\nreturn outData;<br \/>\n}<\/p>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below sample code can save a string &#8220;abcdefghijk&#038; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/33"}],"collection":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33"}],"version-history":[{"count":0,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}