Are you sure you have write permissions to that directory? (I notice it's under /Applications, but it's also under xampp, so maybe you do, but I don't know.) Is an exception printed to the console? Are you sure fh is not nil?

--Andy

On Aug 15, 2008, at 6:10 PM, FTB Accounts wrote:

Devon, thanks for your response. However, your suggestion still does not make the code work. No data is written to the file.

/* WRITE DATA TO FILE: THIS IS A TEST */
        [fh writeData:@"THIS IS A TEST"];
        [fh closeFile];

I simply was copying the advice given on a previous post. I have tried just about everything and can get nothing to work? has anyone on this list ever had success in writing to a local file, and if so can you show me the code you used?

Thanks,

Seth



--- On Fri, 8/15/08, Devon Ferns <[EMAIL PROTECTED]> wrote:

From: Devon Ferns <[EMAIL PROTECTED]>
Subject: Re: creating files to write data to?
To: [EMAIL PROTECTED]
Cc: cocoa-dev@lists.apple.com
Date: Friday, August 15, 2008, 2:28 PM
NSFileHandle writeData takes an NSData pointer not a string
and that's
actually not how you do a string, you're missing the @
in front of it.

<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSFileHandle_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileHandle/writeData: >

Devon

FTB Accounts wrote:


/* WRITE DATA TO FILE: THIS IS A TEST */
        [fh writeData:"THIS IS A TEST"];
        [fh closeFile];


ORIGINAL MESSAGE:

I saw this post on the list previously.

However I am still unable to write to a file... I have tried everything...
Here is my code for my main.m file. What am I missing?

I am running a Mac OS X 10.4.11 and editing with Xcode 2.2.1

HERE IS MY CODE FOR main.m:

#import <Cocoa/Cocoa.h>

int main(int argc, char *argv[]) {

/* Define what file to write to on local hard drive...  */
NSString *fname="/Applications/xampp/xamppfiles/htdocs/data/ data.txt";

/* CREAT EMPTY FILE? */
   [@"" writeToFile:fname atomically:NO];

   NSFileHandle *fh=[NSFileHandle fileHandleForWritingAtPath:fname];

/* WRITE DATA TO FILE: THIS IS A TEST */
   [fh writeData:"THIS IS A TEST"];
   [fh closeFile];


   return NSApplicationMain(argc,  (const char **) argv);
}


/* end main.m */
#############################################

Subject: Re: creating files to write data to?
From: Ondra Cada <[EMAIL PROTECTED]>
Date: Fri, 12 Mar 2004 00:37:49 +0100
Ken,

On Thursday, Mar 11, 2004, at 23:51 Europe/Prague, Ken Hawkins wrote:

how can i create a 0 length file that i will throughout the processes of my app write data to. this is mixed string and binary data.

Do you insist on this workflow?

In a vast majority of cases you just write the complete file atomically, like

NSData *d=... the contents of file computed somehow ...
[d writeToFile:FILENAME atomically:YES];

Nevertheless, you can use NSFileHandle

NSString *fname=...;
[@"" writeToFile:fname atomically:NO]; // create the empty file
NSFileHandle *fh=[NSFileHandle fileHandleForWritingAtPath:fname];
...
[fh writeData:... partial contents of file computed somehow ...]; // as many times as you want to
...
[fh closeFile];
---
Ondra Hada
OCSoftware: [EMAIL PROTECTED] http://www.ocs.cz
private [EMAIL PROTECTED] http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | [EMAIL PROTECTED]
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.






_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/aglee%40mac.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to