iphoneinitwithcontentsoffileinitwithcontentsofurl

grabbing data from an internal file


I'm grabbing data from an external file using NSURL with the code below. If i wanted to grab this data from an internal file in my resources folder how would the code be different.

here's the NSURL code:

NSURL *dataUrl = [NSURL URLWithString:@"https://sites.google.com/site/*****/***/file.asc"]; NSString *fileString = [NSString stringWithContentsOfURL:dataUrl encoding:NSUTF8StringEncoding error:nil];

this was my attempt:

NSString *path = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"asc"]; NSString *fileString = [NSString initWithContentsOfFile:path];

thanks in advance


Solution

  • Maybe try stringByExpandingTildeInPath
    something like

        NSString *path = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"asc"];
        path = [path stringByExpandingTildeInPath];
        NSString *fileString = [NSString initWithContentsOfFile:path];