tags:

views:

1928

answers:

4

hi all, i am new to iPhone Programming i want to read the content of text file which is in my Resourse folder. i do lot of googling but failed to get proper way for doing this task. Please suggest

+1  A: 

Here you go.

luvieere
+1  A: 
Tim
A: 

Tim has already mentioned about NSBundle. If the text file happens to be (or can be) and XML file you may also find this useful

Phil Nash
+3  A: 

The files in your "Resource folder" are actually the contents of your application bundle. So first you need to get the path of the file within your application bundle.

NSString* path = [[NSBundle mainBundle] pathForResource:@"filename" 
                                                 ofType:@"txt"];

Then loading the content into a NSString is even easier.

NSString* content = [NSString stringWithContentsOfFile:path
                                              encoding:NSUTF8StringEncoding
                                                 error:NULL];

As a bonus you can have different localized versions of filename.txt and this code will fetch the file of the currently selected language correctly.

PeyloW