[Newbie] Basic file handling questions...
[Newbie] Basic file handling questions...
- Subject: [Newbie] Basic file handling questions...
- From: Martin-Luc Girard <email@hidden>
- Date: Thu, 8 Nov 2001 10:09:07 -0500
[sorry if this got through multiple times... mail.app keeps showing it
as unsent]
Hello all!
A recent question on this list (re: Newbie, Q about files) sparked my
interest in file handling... now I'm pretty much illiterate as far as
objective C is concerned (coming from a C/C++ (ugh) background) and
I've been trying to figure out from the documentation how all this would
work...
What I'm trying to do is read from a plain text file containing 50
characters per line, and this, one line at a time...
First of all, am I doing this correctly when opening my file?
NSString *filePath= @"~/database.txt";
NSMutableString *fileContents= [[NSMutableString alloc]
initWithString: @""];
NSFileHandle *theFile;
theFile = [NSFileHandle fileHandleForReadingAtPath: filePath];
Is the file actually opened here? if not, how do I open it for reading
plain text?
Then, how would I actually read plain text? here i'm trying to read a
single-line text file...
[fileContents initWithCString:[theFile readDataToEndOfFile]];
definitely does not work...
How would I read a 50 character lines?
Finally, to close the file... is the following correct?
[theFile closeFile];
A basic example would be greatly appreciated...
Thanks for your help!
cheers!
ML