The following is a simple but fully working Java program that demonstrates my issue:
package bufferedreader_test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BufferedReaderTest {
public static void main(String[] args) {
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String line[] = new String[2];
for (int i=0; i<2; i++)
line[i] = br.readLine();
for (int j=0; j<line.length; j++)
System.out.println(line[j]);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
If you copy & paste 2 lines into the console, it will not print them immediately but rather wait for you to hit the Enter
key (i.e. inject a newline into stdin).
For example:
Is there a way to "trick the system" into printing the result as soon as the 2nd line is read, without waiting for the Enter
key (3rd line?) ?