Environment: input file redirection used while running the program, IDE: Eclipse.
I'm reading packets from System.in (since input redirection is used), and counting the number of packets. I get different counts(all wrong) each time I run the program for the same input. Also, I get the correct count when I display a lot of things on the console.
int packetNumber = 0;
while(System.in.available()>0)
{
System.out.println("\n" + packetNumber + ": ");
int numberOfBytes = System.in.read();
byte[] buffer = new byte[numberOfBytes];
System.in.read(buffer, 0, numberOfBytes);
packetNumber++;
}
System.out.println("Number of packets = " + packetNumber);
Working fine with the System.out.println(), but acting weird without it
Thanks in advance.