Dawson
Dawson

Reputation: 73

How to use method stringWithContentsOfFile:encoding:error

I don't know how to use this method.

I want to get the data in an rtf file as a NSString, however 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 can't readout the data in that .rtf file. I am appreciate that everyone may help me. Thanks.

Upvotes: 4

Views: 3748

Answers (2)

PgmFreek
PgmFreek

Reputation: 6402

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

Upvotes: 2

GameLoading
GameLoading

Reputation: 6708

Here is the function

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

before using this be sure u giving a right path (filepath) to the string.

Upvotes: 0

Related Questions