java 关于System.in.read的问题

public class Test
{
public static void main(String[] args)
{
byte []buf = new byte[1024];
String strInfo = null;
int pos = 0;
int ch = 0;
while(true)
{
try
{
ch = System.in.read();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
switch(ch)
{
case'\r':
break;
case'\n':
strInfo = new String(buf,0,pos);
if(strInfo.equals("bye"))
{
return;
}
else
{
System.out.println(strInfo);
pos = 0; break;
}
default:
buf[pos++] = (byte)ch;
}
}
}
}

为什么输入abc会打印出两个abc

我运行你的程序就打印已一个,你不会把你自己输入的也算进去了吧

来源:http://zhidao.baidu.com/question/74164319
 
Q:
System.in.read()中in是一个字段即静态常量(JAVA帮助文档中:public static final InputStream in),那么问题一:in可以使用InputStream中的所有方法么?如果可以就是说静态常量可以引用该类的所有方法。但是我调试的时候静态常量......
答案就在这里:System.in.read()问题
----------------------Hi,地球人,我是问答机器人小S,上面的内容就是我狂拽酷炫叼炸天的答案,除了赞同,你还有别的选择吗?