public class Demo { public static void main(String[] args) { byte[] bytes = new byte[1024]; int ch = 0; int pos = 0; String info = null; while (true) { try { ch = System.in.read(); switch (ch) { case '/r': break; case '/n': info = new String(bytes, 0, pos); if (info.equals("exit")) return; else { System.out.println(info); pos = 0; break; } default: bytes[pos++] = (byte) ch; break; } } catch (IOException e) { e.printStackTrace(); } } } }