Try this code... and then compare it to what you've written:

/* By the way: even this code will give you errors... PLEASE check your console... because you are creating autorelease objects BEFORE you create an autorelease pool and that will ALWAYS spam you console with warnings... methinks you're not looking in the right place if you say the compiler didn't give you any warnings with your code and that you got no errors when you
    ran your code... /jason */

#import <Cocoa/Cocoa.h>

int main (int argc, char const *argv[])
{
        // path of the file to write to
        NSString *path = @"/Users/cknorr/mytest/MYTEST/data.txt";
        
        // contents of the file
        NSString *data = @"THIS IS A TEST";
        
        // write operation
        NSError *error = nil;
if( ![data writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error] ) {
                NSLog(@"Error writing file: %@", [error localizedDescription]);
        } else {
                NSLog(@"File successfully written to %@", path);
        }
        
        return NSApplicationMain(argc, (const char**)argv);
}

On Aug 17, 2008, at 01:07 , FTB Accounts wrote:

Thanks, all for the responses.

First I changed the path to write to. The folder is writable. On GetInfo for the folder "MYTEST", I have set "Read & Write" permissions for: You can, Owner, Group, & Others. Is there anything else I need to do to make it write to that folder?

As a side note, I am running an Apache server on the mac I am working on, and I can write PHP programs that will write to this directory.

However, this is still not working. I am not getting anything under "Errors and Warnings" in Xcode. Also the program loads. However, after running the Debugger does come up.

On debugger there are 5 listed.

0. asm objc_msgSend 0x90a594c0:1
1. ?
2. asm -[NSConcreteFileHandle initWithPath:flags:createMode:] 0x92867509:1
3. asm +[NSFileHandle fileHandleForWritingAtPath:] 0x9287a5e6:1
4. THIS IS BROKEN DOWN IN SUB SECTIONS

[Arguments]
Value: 1
Variable: argc
Value: 0xbffffa5c
Variable: argv
[Locals]
Value: 0x2cf58
Variable: fname
Summary: {(int)[$VAR length]} bytes
Value: 0x1f4c
Variable: fh
Summary: file descriptor: {(int)[$VAR fileDescriptor]}


Here is the current code I am running:

/* START CODE */

#import <Cocoa/Cocoa.h>

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

        NSData *fname = "file:///Users/cknorr/mytest/MYTEST/data.txt";
        NSFileHandle *fh=[NSFileHandle fileHandleForWritingAtPath:fname];
        [fh writeData:@"THIS IS A TEST"];
        [fh closeFile];
        
   return NSApplicationMain(argc,  (const char **) argv);
}



--- On Sat, 8/16/08, Jason Coco <[EMAIL PROTECTED]> wrote:

From: Jason Coco <[EMAIL PROTECTED]>
Subject: Re: creating files to write data to?
To: "Andy Lee" <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED], cocoa-dev@lists.apple.com
Date: Saturday, August 16, 2008, 3:33 AM
On Aug 15, 2008, at 19:35 , Andy Lee wrote:

On Aug 15, 2008, at 6:43 PM, Jason Coco wrote:
Adding the @ just makes it an NSString constant...
but writeData
still requires (NSData *), not (NSString *).

Argh!  Or perhaps, given the nature of this error,
which I missed, I
should say "Arg!"

Surely you got a compiler warning?  If you ignored
that, surely a
runtime error?

Check your errors, both at compile time and runtime
(and treat
warnings as errors).

Yeah... I was thinking the same thing... you /must/ have
got
warnings... eventually you would have gotten an Exception I
think :)




Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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