Hi guys I am currently using BufferedReader
to read files. I have something like:
br.readLine() != null
for each call loop.
And now what should I do if I want to skip a line. Here, I've read several similar questions other people posted, most of them suggested using readLine()
.
I know calling readLine()
once will cause the pointer to the next line. But this is not preferred as I am considering the reading performance here. Although you seem to skip a line, the system actually read it already, so it is not time-efficiency. What I want is to move the pointer to the next line, without reading it.
Any good idea?
If you care about the memory wasted in the intermediate
StringBuffer
, you can try the following implementation:Seems that it works nicely for all the EOLs supported by
readLine
('\n'
,'\r'
,'\r\n'
).As an alternative you may extend the
BufferedReader
class adding this method as instance method inside it.