关于String(bytes,0,n)求助
主函数代码如下
public class Echo {
public static void main(String[] args) {
InputStream is=System.in;
byte[] bytes=new byte[1024];
int n=0;
String input="h";
try {
System.out.println("请输入字符串");
while((n=is.read(bytes))!=-1)
{
input=new String(bytes,0,n);
System.out.println("输入的字符串是"+input);
}
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
问题:1,输入字符串后也显示出来了,可为啥程序没有结束,eclipse 中terminate那个红点还亮着。
2、为啥把“System.out.println("输入的字符串是"+input);"剪切到while循环之后就不能显示输入的字符串了
学生求助,大神勿笑