1 import java.io.File;
2 import java.io.InputStream;
3 import java.io.PrintStream;
4 public class PrintDemo {
5 public static void main(String[] args) throws Exception{
6 InputStream ipt=System.in;//通过键盘接收
7 StringBuffer buf=new StringBuffer();
8 System.out.print("请输入:");
9 int tp=0;
10 while((tp=ipt.read())!=-1){//循环接收
11 char c=(char) tp;//将数据变为字符
12 if(c=='\n'){//按enter键退出循环
13 break;
14 }
15 buf.append(c);//追加数据
16 }
17 System.out.println("输入的内容为:"+buf);
18 ipt.close();
19 }
20 }