What i want to do is, when I used an initialised bufferedReader
which i used to read the lines from a file using readLine()
, when I reach the end of file i want to use the same bufferedReader
object to read lines from the beginnig of the same file for an example.
what i attempted to achieve this matter is, I used mark()
and reset()
, after initialising the bufferedReader
I set bufferReaderobject.mark(0)
and I read the entire file and after that I used bufferReaderobject.reset()
and agian read the entire file but then an exception was thrown. it seems that reset()
only valid when the end of file has not reached.
is there any way to reset a previously initialised bufferedReader
to the beginnig of the stream?
To be able to use reset()
in such a way, the whole file must fit into the buffer of the BufferedReader
.
That means you must either create a BufferedReader
with a buffer that is large enough or create a new instance when you want to read the file again.