Reading from standard input

Following the standard I/O model, Java has System.in, System.out, and System.err. Throughout this book, youve seen how to write to standard output using System.out, which is already prewrapped as a PrintStream object. System.err is likewise a PrintStream, but System.in is a raw InputStream with no wrapping. This means that although you can use System.out and System.err right away, System.in must be wrapped before you can read from it.

Typically, youll want to read input a line at a time using readLine( ), so youll want to wrap System.in in a BufferedReader. To do this, you must convert System.in to a Reader using InputStreamReader. Heres an example that simply echoes each line that you type in: