读取任意长度的字符串

InputStream input = System.in;
StringBuffer buf = new StringBuffer();
System.out.println("请输入内容:");
int temp = 0;
while((temp = input.read()) != -1){
char c = (char) temp;
if(c=='\n'){
break;
}
buf.append(c);
}
System.out.println("输入的内容为:"+buf.toString());
input.close();

你可能感兴趣的:(读取任意长度的字符串)