import java.io.*;
class ReadIn
{
public static void main(String[] args) throws IOException
{
//键盘录入
//System.out :对应的是标准输出设备
//System.in :对应的是标准的输入设备
//InputStream in = System.in;
//int by = in.read();
//System.out.println(by); //r-13 n-10 1-49 1-97
//需求,(1)通过键盘录入数据,录入后一行就打印,如果结果为over那么就停止
/*
InputStream in = System.in;
StringBuffer sb = new StringBuffer();
while (true)
{
int ch = in.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);
}
*/
//(2)同样的要求,操作方法是将字节流转换成字符流
InputStream in = System.in;
InputStreamReader s = new InputStreamReader(in);
BufferedReader buf = new BufferedReader(s);
String line = null;
while ((line = buf.readLine())!=null)
{
if ("over".equals(line))
break;
System.out.println(line);
}
buf.close();
}
}
|
|