1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
// ConsoleIO.java - Reads and prints lines from/to console.
// Fred Swartz - 2002-10-29
import java.io.*;
class ConsoleIO {
public static void main(String[] args) throws IOException {
// In order to read a line at a time from System.in,
// which is type InputStream, it must be wrapped into
// a BufferedReader, which requires wrapping it first
// in an InputStreamReader.
// Note the "throws" clause on the enclosing method (main).
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(isr);
String line; // holds each input line
// Read and print lines in a loop.
// Terminate with control-Z (Windows) or control-D (other)
while ((line = input.readLine()) != null) {
System.out.println(line); // process each line
}
}//end main
}//end class ConsoleIO |