Read line and a byte from console as user input in Java
Description
The following code shows how to read line and a byte from console as user input.
Example
//w w w . jav a 2 s .c om
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] a) throws Exception {
System.out.print("Type some characters and press Enter: ");
BufferedReader bisr = new BufferedReader(new InputStreamReader(System.in));
String response = bisr.readLine();
System.out.println("You typed: '" + response + "'");
System.out.print("Type one character and press Enter: ");
byte b = (byte) System.in.read();
System.out.println("First byte of your input is: " + b);
}
}
The code above generates the following result.