Read string from a file return nil

YosiFZ

I try to read string from a file with :

NSString* path = [[NSBundle mainBundle] pathForResource:@"dirty" ofType:@"txt"];
NSString* content = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&err];

And the string i get is nil. in the error i get :

Error Domain=NSCocoaErrorDomain Code=261 "The operation couldn’t be completed. (Cocoa error 261.)" UserInfo=0x21063410 {NSFilePath=/var/mobile/Applications/78889F89-B83C-480C-A246-999152EE757C/Myapp.app/dirty.txt, NSStringEncoding=4}

Any idea what is the problem?

Amar

As mentioned, Cocoa error 261 is NSFileReadInapplicableStringEncodingError which means the encoding of file is different than what you are passing in the API.

For Hebrew language encoding, try this answer

NSString* content = [[NSString alloc] initWithContentsOfFile:path encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsHebrew) error:&err];

Hope that helps!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Ruby: return the first character from string if it matches and if there is no match then return nil?

From Dev

Ruby: return the first character from string if it matches and if there is no match then return nil?

From Dev

Cython read binary file into string and return

From Dev

read a file and find if a string exists and return the tablename

From Dev

Read string from binary file

From Dev

Read verbatim string from file

From Dev

read string with whitespaces from file

From Dev

Return a string made with a line read from input

From Dev

Read from a file and return output in a vector

From Dev

Remove return key (\n) from read file

From Dev

read() return extra characters from file

From Dev

Read lines from file not return all

From Dev

Read from a file and return new line with loop

From Dev

String interpolation in Typescript with string read from file

From Java

How to Return Nil String in Go?

From Dev

Converting String to URL return nil

From Dev

File.read returning nil

From Dev

Need to read String and Double from file

From Dev

How to Split up a string that was read from a file

From Java

Read and write a String from text file

From Dev

Simple read into string from file Swift OSX?

From Dev

Using goutte to read from a file / string

From Dev

How to read a binary formatted string from a file?

From Dev

Read first n letters from file to a string?

From Dev

Read Connection String From .INI File

From Dev

Python Read String from File with Strange Encoding

From Dev

Java padding a string read from a file

From Dev

Read string from file and convert into an int

From Dev

Passing string Argument, read from a file

Related Related

HotTag

Archive