Why does BufferReader skip some lines when reading a text file in Java?
I am reading data from a text file using BufferReader in Java.
My file contains multiple lines like this:
Ravi,20
Aman,22
Neha,19
I am trying to read and print each line, but some lines are getting skipped.
Here is my code:
BufferReader br = new BufferReader(new FileReader("data.txt"));
String line;
while(br.readLine() != null){
line = br.readLine();
System.out.println(line);
}
Output:
Aman,22
Why are some line skipped and how can I fix this?