主题:高手进
public class ReadLine
{
public static void main (String[] args) {
byte buf[]=new byte [1024];
String strInfo=null;
int pos=0;
int ch=0;
System.out.println("please enter info,input bye for exit;");
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("byte"))
return ;
else
System.out.println(strInfo);
System.out.println(pos);
pos=0;
break;
default:
buf[pos++]=(byte)ch;
}
}
}
}
{
public static void main (String[] args) {
byte buf[]=new byte [1024];
String strInfo=null;
int pos=0;
int ch=0;
System.out.println("please enter info,input bye for exit;");
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("byte"))
return ;
else
System.out.println(strInfo);
System.out.println(pos);
pos=0;
break;
default:
buf[pos++]=(byte)ch;
}
}
}
}