Re: how to deal with files
Re: how to deal with files
- Subject: Re: how to deal with files
- From: Pascal Goguey <email@hidden>
- Date: Sat, 23 Nov 2002 08:15:54 +0900
Hello,
Thanks for the reply! (and thanks to other people who also replied).
I have commented [Data release] and [Path release] but it crashes the
same way. I can follow everything in the debugger as long as I am in
WriteFile. When I leave WriteFile, The window appears, and it is
simply dead. It stays like this forever.
When I don't use the debugger, it exits lke this:
FileTest has exited due to signal 11 (SIGSEGV).
Tanks for any hint.
Pascal
On 土曜日, 11 23, 2002, at 04:07 Asia/Tokyo, Jonathan E. Jackel wrote:
>
Data is autoreleased when it is created. You did not use alloc,
>
copy, or
>
new to create it, so you should not release it. When you release it
>
anyway
>
at the end of WriteFile:, your program crashes.
>
>
Incidentally, I believe initWithCString is deprecated. There's no real
>
point to using a C string in this context anyway. Use
>
>
Path = [NSString stringWithString:@"/Users/pascal/Desktop/helpfile"]
>
>
Just remember the @. You could even do
>
>
Path = @"/Users/pascal/Desktop/helpfile"
>
>
Either way, get rid of [Path release].
>
>
Jonathan
>
>
> - (IBAction)WriteFile:(id)sender {
>
> NSString * Path = [[NSString alloc]
>
> initWithCString:"/Users/pascal/Desktop/helpfile"];
>
> NSData * Data = [NSData dataWithBytes:"help!\n" length:6];
>
> // Create the file object if it does not exist yet
>
> if(mFileHandle == NULL) {
>
> // Check if the file itself exists at the
>
> specified path. If not,
>
> create it
>
> NSFileManager * mFileManager = [NSFileManager
>
> defaultManager];
>
> if([mFileManager fileExistsAtPath: Path] == NO) {
>
> [mFileManager createFileAtPath:Path
>
> contents:nil attributes:nil];
>
> }
>
> // Then at this point, the file exists physically
>
> on the disk
>
> mFileHandle = [NSFileHandle
>
> fileHandleForUpdatingAtPath:Path];
>
> }
>
> [mFileHandle seekToEndOfFile];
>
> [mFileHandle writeData:Data];
>
> [mFileHandle closeFile];
>
> [mFileHandle release];
>
> mFileHandle = NULL;
>
> [Path release];
>
> [Data release];
>
> }
>
>
>
> @end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.