Re: Write to a text file
Re: Write to a text file
- Subject: Re: Write to a text file
- From: Nathan Zamecnik <email@hidden>
- Date: Sun, 05 May 2002 22:44:18 -0500
On 5/5/02 10:19 PM, "Ben O'Neill" <email@hidden> wrote:
>
Hello,
>
I am new to Cocoa and C development.
>
I want to write a text field to a text file when I click the save
>
button. I have been trying to use the NSFileHandle object and writeData
>
however, I can't seem t get it to write the file. Is this the correct
>
approach? Does anyone have some sample code?
>
>
Others have suggested writing my text to an XML file, is this a better
>
approach if I want to save records with fields in a text file?
>
Kind Regards
>
Ben
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
All you have to do is use a method form the NSstring class. Here is the
most basic way to write a string to a file:
[theStringInstance writeToFile:@"Give path here" atomically:YES]
That is all you need to do. Careful though as this will overwrit what is at
that location. I suggest reading the NSString documentation for this to
learn more about it. Also, look into the NSSavePanal class in the AppKit.
That way the user can select where they are going to save and you can write
to that path. Hope this helps a bit.
BTW, the name of the file will be what you set it to, like this:
@"/Users/yourName/directory/theFileName.txt"
That will create a file named FileName.txt
-- NAteZ
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.