Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cazlar

macrumors 6502
Original poster
Oct 2, 2003
492
11
Sydney, Australia
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?
 
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.
 
You might need to send it a synchronizeFile message at the approroate times (it's kind of like stdio's fflush() ).
 
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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.