Quick Cocoa File I/O question

Discussion in 'Mac Apps and Mac App Store' started by cazlar, Aug 8, 2004.

  1. cazlar macrumors 6502

    Joined:
    Oct 2, 2003
    Location:
    Sydney, Australia
    #1
    Hi, I just had a quick question about file I/O in cocoa. In my previous applications I've managed to stick to the general NSData/Dictionary/etc writeToFile:atomically: methods, which work quite well. I'm currently writing an app that will be reading in lots of data over USB (up to multiple GB) in ~64k blocks and I want to write them out one after another. I've had a look at NSFileHandle but a quick test of using it didn't seem to write a file out. Is this where I should be looking or is there some other class that would be of more benefit?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    NSFileHandle is the correct way to go. It may well be buffered (so the data would not show up immediately), or it may write to a hidden/temp file until you close the file (should not do this though). I'd try opening the file, writing a couple of megs then close the file and see what you get.
     
  3. iMeowbot macrumors G3

    iMeowbot

    Joined:
    Aug 30, 2003
    #3
    You might need to send it a synchronizeFile message at the approroate times (it's kind of like stdio's fflush() ).
     
  4. cazlar thread starter macrumors 6502

    Joined:
    Oct 2, 2003
    Location:
    Sydney, Australia
    #4
    great, thanks for the tips!

    edit: I worked out why I wasn't getting the file written out, it because NSFileHandle needs an existing file to work on. As always, RTFM!
     

Share This Page