How to use stringWithContentsOfFile: encoding: error method

I do not know how to use this method.

I want to get data in rtf file as NSString, but I can not.

Here is part of my code.

NSString *filePath = @"path of the file"; NSString *ImagePath = [[[NSString alloc] init] autorelease]; imagePath = [NSString stringWithContentsOfFile: filePath encoding:(NSStringEncoding)nil error:(NSError**) nil]; 

I cannot read the data in this .rtf file. I appreciate that everyone can help me. Thanks.

+4
source share
2 answers

Try using this imagePath = [NSString stringWithContentsOfFile: filePath encoding:NSUTF8StringEncoding error:nil ];

+2
source

Here is the function

 NSString *content = [[[NSString alloc] initWithContentsOfFile:filepath usedEncoding:nil error:nil] autorelease]; 

before using this, make sure u sets the correct path ( file path ).

0
source

Source: https://habr.com/ru/post/1344552/


All Articles