Opening old text files with non-deprecated stringWithContentsOfFile calls?
Michael Dupuis <smokinmonkey-/[email protected]> Mon, 11 Oct 2010 06:50:33 -0700 (PDT)
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
Greetings, The + (id)stringWithContentsOfFile:(NSString *)path call in NSString has been deprecated a while, in favor of the newer calls that either have you specify or that can try and figure out the encodings of files when loading. However, I've noticed that it's very easy to download older text files from the web that fail to import with an "Error Domain=NSCocoaErrorDomain Code=264 UserInfo=0x14c1d9a0 "The file “file.txt” couldn’t be opened because the text encoding of its contents can’t be determined." error or similar. The deprecated call opens these files without a problem. I tried various ways to open them, using NSData, etc. but unless you open them in something like TextWrangler and save them with a specific encoding, they all seem to fail to load. Has anyone figured out what needs to be done to open files the way the deprecated call does? There must be some fallback when there is no encoding that can be done, but I can't seem to figure out what that is... Are people just basically forced to use files with specified encodings now? Thanks, Michael