PDA

View Full Version : pathForResource is not working...?




detz
Oct 14, 2008, 08:27 AM
NSString *resource = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"];
NSString *content = [NSString stringWithContentsOfFile:resource];

there is a test.txt file in my Resource directory but both of these values are nil. Any ideas?



robbieduncan
Oct 14, 2008, 09:11 AM
Are you 100% sure it's called "test.txt" not "Test.txt" or "test.TXT" for example?

lawicko
Oct 14, 2008, 09:27 AM
I notice that sometimes there is a problem if you release the path to the resource to early, so try not to release resource string before you actually use content object.

detz
Oct 14, 2008, 09:44 AM
Weird, I tried everything and the only thing that worked was deleting the txt file and re-creating it. Maybe there was an encoding issue or something.

PhoneyDeveloper
Oct 14, 2008, 11:19 AM
NSString stringWithContentsOfFile: is deprecated and there's no reason that you should use it. Use stringWithContentsOfFile:encoding:error: