Re: Save to file or db
Re: Save to file or db
- Subject: Re: Save to file or db
- From: Simon Davies <email@hidden>
- Date: Wed, 28 Feb 2007 14:03:59 +0000
Thanks Jim
Thanks for the information, your not teaching me to fish at all, I am a
very neebie to it all, can't even place the worm on the hook.:-)
the second one worked it was an error of mine I had an error and removed
it and the.txt bit thinking it was this as well, and never thought to
try it again.thanks
1)As for this one I am using a bluetooth discovery program, and
display. But I also would like to save the device name, address and
time/date onto a file or db, so it could write to the file out about 10
plus times for every discovery so it would be nice to append and new
line to the data etc will give your links ago.
Jim Thomason wrote:
In the hopes of teaching a man to fish....replies are below.
On 2/28/07, Simon Davies <email@hidden> wrote:
i have seemed to have saved some variable to file using :
NSString* myTextToWrite = @"welcome to my file, its writing juxt need it
to do the rest";
[myTextToWrite writeToFile:[NSHomeDirectory()
stringByAppendingPathComponent: @"Desktop/mytext"] atomically:YES];
1) My next two questions relating to this is what do I need to add to
this to append the text to previous text on the file?
You can't add onto the file using NSString's writeToFile:.. method,
only clobber an existing one. You can look at using NSFileHandle to
open up a file handle and send your data across to it, but since
you've got such a small amount of data (two short strings and a date,
right?), it'd be much simpler to just build up a string yourself and
then use writeToFile:... to send that out to disk. Hint - look at
NSString's +stringWithFormat: I recommend downloading Appkido, if you
don't have it already. Makes all this class hunting easier.
2) The file"mytext" that it writes on has no extension which it still
opens in textedit but to be used by another program I think i need the
extension ".txt" can this be acheived at all?
You don't necessarily need the .txt extension. It depends upon the
program. The solution is that you have to write out to the filename
_exactly_ as you want it to appear on disk. So you want to create
"~/Desktop/mytext.txt", and you're currently writing out to
"~/Desktop/mytext". The necessary changes are left to the reader. :-)
-Jim....
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden