This time I have a very lame problem, which was working perfectly but now its not:
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
while (br.readLine() != null) {
System.out.println(br.readLine());
}
Input file:
1
2
3
4
5
6
7
8
9
In command line: $java myprogram < inputfile
The result of the above written code is:
2
4
6
8
null
But the expected output should be same as input file!
Where am I going wrong?!
You are calling br.readLine() twice. It’s calling it once in the while condition and once to actually print it out. That’s why you are only printing every other line.
Edit: Your condition should be: