I am reading a txt file with a very simple code. The problem is that in the Log statments I only get the path of the file but contents are null. I guess that the problem lies in encoding part.Any Suggestions on how to read my text file.
NSStringEncoding encoding;
NSString* content;
NSString* path = [[NSBundle mainBundle] pathForResource:@"colorpalette" ofType:@"txt"];
if(path)
{
content = [NSString stringWithContentsOfFile:path usedEncoding:&encoding error:NULL];
}
NSLog(@"path is %@",path);
if (content)
{
NSLog(@" content of file is %@",content);
}
Here encoding parameter is not set properly.
Try this
NSString* content = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:NULL];
NSLog(@"%@",path);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With