Can we skip EOF when reading input?

79 Views Asked by At

After I catch eof, if I try to read information from input again, I no longer get new information. Is there any way I can resume reading the data?

Scanner s = new Scanner(System.in);
while (s.hasNextInt()) {
    A[i] = s.nextInt();
    i++;
}

But in applications, when I press ctrl D(EOF in Windows), it does not stop working, for example, in Intellij idea, which is also written in java.

Or a terminal to which I can send EOF, and it will continue to receive information. As a result, how can I process the eof from the user so that my application continues to work?

1

There are 1 best solutions below

7
queeg On

If a stream indicates EOF it means you consumed it all. There is nothing else to be read. If the stream implementation allows, you might 'rewind' the stream and read the same bytes again. Otherwise just close it.

It's similar to having eating all the bread. After that there is no more bread to eat. Move on, find something else to eat.