FROM : Pascal Goguey
DATE : Fri Nov 22 17:52:45 2002
Hello,
I am new to Cocoa, and I am trying to figure out how to work with
files. I wrote a simple test. One GUI with a single button. One object
(see below). The button calls the method WriteFile, and that's
about it.
Everytime I push the button (the only one), it should write one
line at the end of the file. The code of the object is listed below.
The problem is that the program exits after the first button press.
Any hint?
Thanks,
Pascal
---------------
/* FileObject */
#import <Cocoa/Cocoa.h>
@interface FileObject : NSObject {
IBOutlet id mWriteButton;
NSFileHandle * mFileHandle;
}
- (IBAction)WriteFile:(id)sender;
@end
---------------
#import "FileObject.h"
@implementation FileObject
- (void)awakeFromNib {
mFileHandle = NULL;
}
- (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_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
DATE : Fri Nov 22 17:52:45 2002
Hello,
I am new to Cocoa, and I am trying to figure out how to work with
files. I wrote a simple test. One GUI with a single button. One object
(see below). The button calls the method WriteFile, and that's
about it.
Everytime I push the button (the only one), it should write one
line at the end of the file. The code of the object is listed below.
The problem is that the program exits after the first button press.
Any hint?
Thanks,
Pascal
---------------
/* FileObject */
#import <Cocoa/Cocoa.h>
@interface FileObject : NSObject {
IBOutlet id mWriteButton;
NSFileHandle * mFileHandle;
}
- (IBAction)WriteFile:(id)sender;
@end
---------------
#import "FileObject.h"
@implementation FileObject
- (void)awakeFromNib {
mFileHandle = NULL;
}
- (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_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
| Related mails | Author | Date |
|---|---|---|
| Pascal Goguey | Nov 22, 17:52 | |
| Marco Binder | Nov 22, 18:35 | |
| Jonathan E. Jackel | Nov 22, 20:07 | |
| Pascal Goguey | Nov 23, 00:15 |






Cocoa mail archive

