Reading Text from Standard Input

BufferedReader inStream = new BufferedReader (
											new InputStreamReader(System.in)
											);
											String inLine = "";
											while ( !(inLine.equalsIgnoreCase("quit"))) {
											System.out.print("prompt> ");
											inLine = inStream.readLine();
											}

In a console program, it is common to read from the standard input, typically the command line. In this phrase, we show how you can read the standard input into a Java String variable.

Java contains three streams that are connected to the operating system streams. These are the standard input, standard output, and standard error streams. Respectively, they are defined in Java as the streams System.in, System.out, and System.err. We can make use of these streams to read or write to the operating systems ...

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.