Re: Read Total lines in an ASCII file [message #33335 is a reply to message #33175] |
Wed, 18 December 2002 13:04   |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
"Paul Woodford" <cpwoodford@spamcop.net> wrote in message
news:cpwoodford-C4345E.22403817122002@corp.supernews.com...
> Would it be possible to find the length of the file, read it into to
> a byte array, and then convert it to text?
Yes, but:
- If you take the 1D byte array that would result from reading the
file and convert it to a string, then you don't get a string array,
you just get a string with line-separator characters in it. So
there's a bit of splitting to be done, and you really should handle
the various line separators supported by the different platforms.
- It doesn't work on compressed files, because you don't know how
many bytes there are in a compressed file until you've read it. So
you have to read the byte data in chunks, trap the error when the
final read hits the end of the file, and join the chunks together.
> Paul, who is too lazy to figure it out himself
Mark, who has thought about it, but can't be bothered actually trying
it.
--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|