Re: creating files to write data to?

  • 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...>
    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...> http://www.ocs.cz
    private <email...> http://www.ocs.cz/oc
    _______________________________________________
    cocoa-dev mailing list | <email...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Aug 14, 2008, at 6:42 PM, FTB Accounts wrote:

    > 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?

    For starters, NSString constants have to begin with an @ sign, or they
    will be treated by the compiler as C char array constants, which are
    not the same as NSString constants. In other words:

    @"This is an NSString constant string."
    "This is a C char array constant string."

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • 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/NSFileHa
    ndle/writeData:
    >

    Devon

    FTB Accounts wrote:

    >
    > /* WRITE DATA TO FILE: THIS IS A TEST */
    > [fh writeData:"THIS IS A TEST"];
    > [fh closeFile];
    >
  • 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 <dferns...> wrote:

    > From: Devon Ferns <dferns...>
    > Subject: Re: creating files to write data to?
    > To: <ftbaccounts...>
    > Cc: <cocoa-dev...>
    > 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/NSFileHa
    ndle/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...>
    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...> http://www.ocs.cz
    private <email...> http://www.ocs.cz/oc
    _______________________________________________
    cocoa-dev mailing list | <email...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • 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 <dferns...> wrote:
    >
    >> From: Devon Ferns <dferns...>
    >> Subject: Re: creating files to write data to?
    >> To: <ftbaccounts...>
    >> Cc: <cocoa-dev...>
    >> 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/NSFileHa
    ndle/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...>
    > 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...> http://www.ocs.cz
    > private <email...> http://www.ocs.cz/oc
    > _______________________________________________
    > cocoa-dev mailing list | <email...>
    > Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
  • Also:

    You should add a check for the return value from your call to -
    writeToFile:atomically: (which is deprecated, by the way).  The docs
    for +fileHandleForWritingAtPath: say it returns nil if the file
    doesn't exist (which might be the case if -writeToFile:atomically:
    failed), so you should check the return value from that too.

    In general, you should check the results of I/O operations, and don't
    assume they succeed.

    --Andy
  • On Aug 15, 2008, at 18:10 , 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?

    Adding the @ just makes it an NSString constant... but writeData still
    requires (NSData *), not (NSString *). As was pointed out before, are
    you sure that you have
    write permissions here? You should check your errors... also, try
    writing the location with basic system calls (just to test briefly)
    and check the return result and the
    errno to see what might be the issue...?

    Following up on what another poster suggested, is it possible to do
    this another way? For instance, if you are storing strings and binary
    data, is it possible to
    write this file using an (NSMutableDictionary *)? You could write both
    your strings (NSString *) and data (NSData *) to a structure in memory
    (if you don't have keyed data, just use (NSMutableArray *) instead of
    (NSMutableDictionary *). If you're afraid of losing data or have to
    share the data through the file, maybe you could flush it every
    time you make a change? Both the array and the dictionary respond to -
    (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag

    /jason
  • 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).

    --Andy
  • 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 :)
  • 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 <jason.coco...> wrote:

    > From: Jason Coco <jason.coco...>
    > Subject: Re: creating files to write data to?
    > To: "Andy Lee" <aglee...>
    > Cc: <ftbaccounts...>, <cocoa-dev...>
    > 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 :)
  • On Aug 17, 2008, at 12:07 AM, FTB Accounts wrote:

    > Here is the current code I am running:

    This code has many fundamental errors.  I think you need to review the
    basics of the C language first, then of Objective-C.  You have to walk
    before you can run.

    You say that you're not getting any errors or warnings when you build
    this, but that can't be.  You would definitely get warnings for this
    code.

    > /* START CODE */
    >
    > #import <Cocoa/Cocoa.h>
    >
    > int main(int argc, char *argv[])
    > {
    >
    > NSData *fname = "file:///Users/cknorr/mytest/MYTEST/data.txt";

    You are initializing a variable of type NSData* (pointer to NSData).
    However, the right-hand side is not an NSData*, it's a C-style string,
    which is a character array (char* or char[]).  These are not
    compatible.  It's certainly not meaningful.  Any attempt to use the
    fname variable as though it were a pointer to an NSData object would
    fail, because it doesn't actually contain a valid pointer to an NSData
    object.

    > NSFileHandle *fh=[NSFileHandle fileHandleForWritingAtPath:fname];

    Even if fname did contain a valid pointer to an NSData object, the
    above would not be correct.  The +fileHandleForWritingAtPath: method
    of NSFileHandle expects a pointer to an NSString object as its
    argument, but that's not what you're providing.

    Note that a pointer to a C-style string (character array), which is
    what's in fname, is also _not_ a valid pointer to an NSString object.
    They are two completely different ways of representing strings and are
    not directly interchangeable.

    > [fh writeData:@"THIS IS A TEST"];

    The -writeData: method of NSFileHandle expects a pointer to an NSData
    object.  However, what you're passing here is a pointer to an NSString
    object.  Again, this can't work.

    >
    > [fh closeFile];
    >
    > return NSApplicationMain(argc,  (const char **) argv);
    > }

    Regards,
    Ken
  • On 17-Aug-08, at 1:52 AM, Ken Thomases wrote:

    > On Aug 17, 2008, at 12:07 AM, FTB Accounts wrote:
    >
    >> Here is the current code I am running:
    >
    > This code has many fundamental errors.  I think you need to review
    > the basics of the C language first, then of Objective-C.  You have
    > to walk before you can run.
    >
    > You say that you're not getting any errors or warnings when you
    > build this, but that can't be.  You would definitely get warnings
    > for this code.
    >
    >> /* START CODE */
    >>
    >> #import <Cocoa/Cocoa.h>
    >>
    >> int main(int argc, char *argv[])
    >> {
    >>
    >> NSData *fname = "file:///Users/cknorr/mytest/MYTEST/data.txt";
    >
    > You are initializing a variable of type NSData* (pointer to
    > NSData).  However, the right-hand side is not an NSData*, it's a C-
    > style string, which is a character array (char* or char[]).  These
    > are not compatible.  It's certainly not meaningful.  Any attempt to
    > use the fname variable as though it were a pointer to an NSData
    > object would fail, because it doesn't actually contain a valid
    > pointer to an NSData object.
    >
    >> NSFileHandle *fh=[NSFileHandle fileHandleForWritingAtPath:fname];
    >
    > Even if fname did contain a valid pointer to an NSData object, the
    > above would not be correct.  The +fileHandleForWritingAtPath: method
    > of NSFileHandle expects a pointer to an NSString object as its
    > argument, but that's not what you're providing.

    and file:/// is a URL string, not a file system path.
  • Hi,

    I couldn't believe that you didn't get any warning so I did copy your
    code into xcode. Voila, I do get warnings!

    My suggestion is read again the comments carefully and check the
    documentation.

    It was mentioned before that [fh writedata ... needs a NSData ( or
    NSMutableData ) and not a string.

    Also check the docs for [NSFileHandle fileHandleForWritingAtPath:] it
    needs a string. So fname should be a string.

    You know that you can select the text in your code and then right/
    control click to go to 'Find selected text.....'?

    If you do then you can see that you need a NSString with the path and
    not a URL.

    Also don't forget, that if your file does not exist, *fh will be nil!!

    Good luck.

    R

    On 17 aug 2008, at 07: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 <jason.coco...> wrote:
    >
    >> From: Jason Coco <jason.coco...>
    >> Subject: Re: creating files to write data to?
    >> To: "Andy Lee" <aglee...>
    >> Cc: <ftbaccounts...>, <cocoa-dev...>
    >> 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 :)

    >
  • 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 <jason.coco...> wrote:
    >
    >> From: Jason Coco <jason.coco...>
    >> Subject: Re: creating files to write data to?
    >> To: "Andy Lee" <aglee...>
    >> Cc: <ftbaccounts...>, <cocoa-dev...>
    >> 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 :)
    >
    >
    >
previous month august 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today