public class ReadLine {
public static void main(String[] args) {
// TODO Auto-generated method stub
byte buf[] = new byte[1024];
String strInfo = null;
int pos = 0;
int ch = 0;
System.out.println("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 ("bye".equalsIgnoreCase(strInfo))
return;
else
System.out.println(strInfo);
pos = 0;
break;
default:
buf[pos++] = (byte) ch;
}
}
}}
public static void main(String[] args) {
// TODO Auto-generated method stub
byte buf[] = new byte[1024];
String strInfo = null;
int pos = 0;
int ch = 0;
System.out.println("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 ("bye".equalsIgnoreCase(strInfo))
return;
else
System.out.println(strInfo);
pos = 0;
break;
default:
buf[pos++] = (byte) ch;
}
}
}}
如有错误之处, 欢迎大家指出讨论...