1

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

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
hanumanDev
  • 6,592
  • 11
  • 82
  • 146

1 Answers1

2

Maybe try stringByExpandingTildeInPath
something like

    NSString *path = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"asc"];
    path = [path stringByExpandingTildeInPath];
    NSString *fileString = [NSString initWithContentsOfFile:path];
filipe
  • 3,370
  • 1
  • 16
  • 22
  • thanks for replying. I tried it, but get a warning: 'NSString' may not respond to '+initWithContentsOfFile:' – hanumanDev Aug 18 '10 at 17:35
  • have you tried "- (id)initWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError **)error"? – filipe Aug 18 '10 at 18:25