package string.itcastio; import java.io.*; /* * 当录入一行数据后,就将该行数据经行打印 * 如果录入的数据是over,那么停止录入 */ public class IODemo1 { public static void main(String[] args) throws IOException { InputStream is = System.in; StringBuilder sb = new StringBuilder(); while (true) { int ch = is.read(); if (ch == '\r') continue; if (ch == '\n') { String s = sb.toString(); if ("over".equals(s)) { break; } System.out.println(s); sb.delete(0, sb.length()); } else { sb.append((char)ch); } } } }