|
||
| Module 3 | Reading data from a stream Setting an end-of-stream flag |
|
If read() encounters the end-of-stream, it returns -1 instead. You use this as a flag to watch for the end-of-stream.
int[] b = new int[10]; for (int i = 0; i < b.length; i++) { int datum = System.in.read(); if (datum == -1) break; b[i] = datum; } |
||
|
|
||