1)Can you explain why the pointer(reference) associated with readLine method doesn't come again to the first character?
2)What read() mehthod does??
Why you think readLine() should read the same line again and again or the pointer( reference) assiciated with readLine() should come again to the first character.?
Suppose pointer (reference) points to the first character again come to the first character then how will you read more than one line from the file, since you can not change the reference as I dont think there are methods to set the reference or pointer.
Simple answer to your question is because this is how it has been implemented in Java
read() function will read one character at a time and it will return -1 if end of file is met.
Since the read() method already reads a single character from the stream, then calling readLine() after that continues reading from the stream where it left off last time. Or in other words, lets imagine that the stream position is 0 before the read() method. Now the read() method executes by reading a single character and stream position is now 1. So calling the readLine() starts reading at the second character.
Check the code below:
The output is:
read() reads character 84
readLine() result is: his is first line