谁能帮我解释一下这段程序的意思,详细点,谢谢了。
public class ReadLin {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: Add your code here
byte [] buf=new byte[1024];
String strInfo=null;
int pos=0;
int ch=0;
System.out.println("请输入:");
while(true)
{
try{
ch=System.in.read();
}
catch(Exception e){e.printStackTrace();}
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;
}
}
}
}
public class ReadLin {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: Add your code here
byte [] buf=new byte[1024];
String strInfo=null;
int pos=0;
int ch=0;
System.out.println("请输入:");
while(true)
{
try{
ch=System.in.read();
}
catch(Exception e){e.printStackTrace();}
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;
}
}
}
}
当换行的时候结束,并显示出你所输入的结果啊'r'为换行 break为换行
'n'为回车 buf[pos++]=(byte)ch; 为没有回车换行的时候将一个个字符写入byte数组中当你输入bye时退出程序