Reading text file with NSString:stringWithContentsOfFile?
NSString *txtFilePath = [[NSBundle mainBundle] pathForResource:@"\help" ofType:@"txt"];
NSString *txtFileContents = [NSString stringWithContentsOfFile:txtFilePath encoding:NSUTF8StringEncoding error:NULL];
NSLog(@"File: %@",txtFileContents);
I get “null” as the result. How do I know what path to specify?
thanks
(I placed the file just under “Groups and Files” … so not sure if I need to specify a path or just the file name. Maybe there is something else wrong ???
I think the backslash in your path is confusing things. Try this:
Also, as noted in the comments, you need to use the Build Phase of your project to copy the “help.txt” file.