开发者

grabbing data from an internal file

开发者 https://www.devze.com 2023-01-12 16:12 出处:网络
I\'m grabbing data from an external file using NSURL with the code below. 开发者_如何学JAVAIf i wanted to grab this data from an internal file in my resources folder how would the code be different.

I'm grabbing data from an external file using NSURL with the code below. 开发者_如何学JAVAIf 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


Maybe try stringByExpandingTildeInPath
something like

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

精彩评论

暂无评论...
验证码 换一张
取 消