Re: Reading/Writing Text files
Re: Reading/Writing Text files
- Subject: Re: Reading/Writing Text files
- From: Douglas Davidson <email@hidden>
- Date: Mon, 11 Sep 2006 09:26:49 -0700
On Sep 11, 2006, at 5:29 AM, email@hidden wrote:
I need to read in text files off a PC, manipulate some bytes of
data and then
write the data back out to plain text files. How do I do this? It
seems every
Cocoa application example I look at assumes that you want to use an
encoder,
so all I can find are examples of reading and writing with encoders.
I just want to.
1: Read in the text file into an NSTextView
2: Have the user make some minor changes
3: Write the new data back out (To a Plain text file)
Is this possible??
The easiest way to do this is with NSAttributedString methods. An
NSTextView has an NSTextStorage, which is a direct subclass of
NSMutableAttributedString. You can use, for example,
NSMutableAttributedString methods like -
readFromURL:options:documentAttributes:error:. This method will, if
you choose, read from any text format understood by the text system,
not just plain text.
The most important wrinkle with plain text is that you should,
wherever possible, use NSCharacterEncodingDocumentOption to specify
an encoding for the file--otherwise in most cases the default
encoding will be used, which is probably not what is wanted. You
cannot in general expect to read a plain text file without knowing
its encoding.
You can look at the TextEdit example code for some examples of this
sort of thing in action.
Douglas Davidson
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden