C
Chris Brat
Hi,
I need to find the total number of lines in a text file -so that I can
skip the header and filler information and process just the body.
I've done some searching and can't find a class or method that does
this directly and the solutions I've found require either :
- reading each line of the file (using the BufferedReader) and
incrementing a line counter for each line, or
- using the LineNumberReader directly and using its result from its
getLineNumber() method once the entire file is read, or
- searching for the eol characters and counting these.
- using the the RandomAccessFile, seeking to the end of the file and
dividing the total number of bytes by the number of bytes expected in
the line (I believe this relies on guarantee that each line will have
the same number of characters).
I dont like the idea of counting eol characters or having to read the
entire file twice (once to get the number of line numbers and the
second time to do my actual processing).
Does anyone have another or better solution?
Thanks,
Chris
I need to find the total number of lines in a text file -so that I can
skip the header and filler information and process just the body.
I've done some searching and can't find a class or method that does
this directly and the solutions I've found require either :
- reading each line of the file (using the BufferedReader) and
incrementing a line counter for each line, or
- using the LineNumberReader directly and using its result from its
getLineNumber() method once the entire file is read, or
- searching for the eol characters and counting these.
- using the the RandomAccessFile, seeking to the end of the file and
dividing the total number of bytes by the number of bytes expected in
the line (I believe this relies on guarantee that each line will have
the same number of characters).
I dont like the idea of counting eol characters or having to read the
entire file twice (once to get the number of line numbers and the
second time to do my actual processing).
Does anyone have another or better solution?
Thanks,
Chris