Follow by Email

Search This Blog

Sunday, 27 November 2011

Read/Write text to File in iPhone/iPad app

Here we are sharing how to Create a file and write in it.
 Just copy and paste into .m file in your project

//This is our Writing part:

NSArray *filepath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsdirectory=[filepath objectAtIndex:0];
    NSLog(@"Document directory>>>%@",documentsdirectory);
    NSString *filename=[NSString stringWithFormat:@"%@/myfile.txt",documentsdirectory];
    NSString *content=@"One\nTwo\nThree\nFour\nFive";
    [content writeToFile:filename atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil];

//Writting part end.

//This our Reading part
NSArray *path= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentdir=[path objectAtIndex:0];
    NSString *filename=[NSString stringWithFormat:@"%@/myfile.txt",documentdir];
    NSString *cont=[[NSString alloc]initWithContentsOfFile:filename usedEncoding:nil error:nil];

Reading part end.


  1. Iphone application development to extend the memory configuration for storing files in it.

    iphone app

  2. Appreciated..!! Thank you for this code.

    iPhone App Developers


  3. I have read this blog that provide good information regarding how to Read/Write text to File in iPhone or iPad app with the help of code and which is useful for me or other people.Thanks. .

  4. Indeed! This method is really simple and it will be good for those who are new to iPhone App Development like me.Thanks

  5. Thanks for complements all of you, if you need more so you can suggest me whatever i can share with you it will be my pleasure.

  6. Thanks for sharing information I must say very informative blog post. Keep it up!!
    Hire Angularjs Developers | Truck Dispatch Software | Taxi App Development

  7. We decided to help you out with design portfolio templates, Ideas, and Inspiration for your portfolio. Some of the portfolio designs can also be downloaded as templates which means you can use the design and layout to create your own portfolio from the file.