Re: Re: writing huge C-array to a file
Re: Re: writing huge C-array to a file
- Subject: Re: Re: writing huge C-array to a file
- From: "Michael Ash" <email@hidden>
- Date: Mon, 24 Jul 2006 11:39:07 -0400
On 7/23/06, PGM <email@hidden> wrote:
Thanks for your suggestions. I had already looked into the
documentation of NSFileHandle and NSFileManager, but not being familiar
with fileDescriptors, I did not see any obvious way to do standard C
fprintf writing with the help of those classes.
For the archives, I now use the following code in NSDocument's
"writeToFile:ofType:":
//create new file if it does not yet exist
if(![[NSFileManager defaultManager] fileExistsAtPath:fileName]){
[[NSFileManager defaultManager] createFileAtPath:fileName
contents:[NSData data] attributes:nil];
}
FILE *writing;
NSFileHandle *handle = [NSFileHandle
fileHandleForUpdatingAtPath:fileName];
int descriptor = [handle fileDescriptor];
writing = fdopen(descriptor, "w");
//Now use fprintf for all the writing
fclose(writing);
[handle closeFile];
The above code is entirely overcomplicated. Nothing requires you to
use Cocoa here. You can simplify it down to just:
FILE *writing = fopen( [fileName fileSystemRepresentation], "w" );
// write using fprintf
fclose( writing );
(Note that this replaces the entire code, including the NSFileManager bits.)
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden