Abbey Workshop | ||||||||||
This small program shows how to read a line of text from the console or keyboard using Java. Click on the link below to see the code for this program.
Download source for: ReadLine.java
>java
ReadLine
Enter a line of text (type 'quit' to exit):
Line 1
You typed: Line 1
Line 2
You typed: Line 2
quit
First, input from the keyboard or console is read from the System.in object which functions as standard input. This data is wrapped by an InputStreamReader which reads data one character at a time. To read this data a line at a time, a BufferedReader is wrapped around the InputStreamReader. Using the BufferedReader, a line at a time is read as shown on line 16. If the line is not equal to "quit" it is printed out.
Copyright © Abbey Workshop 2006