| /home/oracle/labs/12-IO_Fundamentals/examples/SystemInputExample/src/com/example/KeyboardInput.java |
1 package com.example;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6
7 public class KeyboardInput {
8
9 public static void main(String[] args) {
10 String s = "";
11 try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
12 System.out.print("Type xyz to exit: ");
13 s = in.readLine();
14 while (s != null) {
15 System.out.println("Read: " + s.trim());
16 if (s.equals("xyz")) {
17 System.exit(0);
18 }
19 System.out.print("Type xyz to exit: ");
20 s = in.readLine();
21 }
22 } catch (IOException e) {
23 System.out.println("Exception: " + e);
24 }
25 }
26 }