Re: Opening old text files with non-deprecated stringWithContentsOfFile calls?
Andy Lee <[email protected]> Mon, 11 Oct 2010 10:10:13 -0400
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
Michael, Can you post some links to such files so we can experiment? Also, do you know what encoding the files are actually using, or at least intending to be using, and do the new calls work if you specify that encoding explicitly? I wonder if the deprecated call succeeds because it guesses the encoding better, or it guesses the encoding incorrectly, or is less strict with incorrectly encoded files. Does TextWrangler guess the encoding correctly? If you dirty the file without actually changing it, and save the file with TextWrangler without changing the encoding, does the resulting file match the original byte for byte? --Andy On Oct 11, 2010, at 9:50 AM, Michael Dupuis wrote: > 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