NSString stringWithContentsOfFile failing with what seems to be the wrong error code

后端 未结 6 1883
闹比i
闹比i 2021-02-12 22:33

I\'m trying to load a file into a string. Here is the code I\'m using:

NSError *error = nil;
NSString *fullPath = [[NSBundle mainBundle] pathForResource:filename         


        
6条回答
  •  一向
    一向 (楼主)
    2021-02-12 22:51

    The most likely reason that +stringWithContentsOfFile:encoding:error: would fail in this case would be if you provided the wrong encoding. Are you sure that your @"eula" file is UTF8 encoded?

    If you're unsure about the encoding of the file, you could always try +stringWithContentsOfFile:usedEncoding:error: instead and see if it works and what encoding it comes up with.

提交回复
热议问题