Re: [Newbie] Basic file handling questions...
Re: [Newbie] Basic file handling questions...
- Subject: Re: [Newbie] Basic file handling questions...
- From: "Erik M. Buck" <email@hidden>
- Date: Thu, 8 Nov 2001 14:06:27 -0600
If your files are short, you can do the folowing:
NSString *fileText = [[NSString alloc] initWithContentsOfFile:somePath];
NSArray *individualLines = [fileText componentsSeparatedByString:@"\n"];
[fileText release];
// individualLines is now an autoreleased array containing one line at each
index in the array
If your files are long, you can use NSScanner or the technique you are
already using.
You can also always use stdio.
FILE *file = fopen(somePath, "r");
if(NULL != file)
{
char buffer[SOME_LARGE_SIZE];
while(NULL != fgets(buffer, SOME_LARGE_SIZE - 1, file)
{
// do something with the one line of text in buffer
}
fclose(file);
}
----- Original Message -----