A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

  1. import java.io.*;
  2. import java.util.*;
  3. class Test_system
  4. {
  5.         public static void main(String args[]) throws IOException
  6.         {
  7.           /* byte[] b=new byte[10];
  8.            int n;
  9.            n=System.in.read(b);
  10.            FileOutputStream fout=new FileOutputStream("a.text");
  11.        fout.write(b);
  12.         fout.close();*/

  13.         FileOutputStream fout=new FileOutputStream("a.text");
  14.         OutputStreamWriter bos=new OutputStreamWriter(fout);
  15.         BufferedWriter bo=new BufferedWriter(bos);
  16.         
  17.         InputStreamReader res=new InputStreamReader(System.in);
  18.         BufferedReader buf=new BufferedReader(res);
  19.         Scanner scanner=new Scanner(System.in);
  20.         System.out.println("信息的读入以Ctrl+c作为结束!");
  21.         do
  22.         {
  23.          String ch=buf.readLine();
  24.           //System.out.println(ch);
  25.         //fout.write(Integer.parseInt(ch));
  26.          
  27.           bo.newLine();
  28.           bo.write(ch);
  29.          
  30.         }
  31.         while(scanner.hasNextLine());
  32.         buf.close();
  33.         bo.close();
  34.         }
  35.   
  36. }
复制代码

4 个回复

倒序浏览
  1. import java.io.*;
  2. import java.util.*;
  3. class Demo
  4. {
  5.         public static void main(String[] args) throws Exception
  6.         {
  7.                 Scanner keyIn=new Scanner(System.in);

  8.                 PrintWriter outText=new PrintWriter(new FileOutputStream("a.txt"),true);

  9.                 String line=null;

  10.                 System.out.println("请输入要录入的内容。输入overin或者按Ctrl+C结束录入");
  11.                
  12.                 while (keyIn.hasNextLine())
  13.                 {
  14.                         line=keyIn.nextLine();
  15.                         if("overin".equals(line))
  16.                                 break;
  17.                         outText.println(line);
  18.                 }
  19.                 keyIn.close();
  20.                 outText.close();

  21.         }
  22. }
复制代码
回复 使用道具 举报
既然楼主都已经用了BufferedRead读取键盘录入。。。
为何还用Scanner呢。。。
还有……楼主取的变量名看得好辛苦……

这是用BufferedRead存储键盘录入的。。。
  1. import java.io.*;
  2. class Demo
  3. {
  4.         public static void main(String[] args) throws Exception
  5.         {
  6.                 BufferedReader keyIn=new BufferedReader(new InputStreamReader(System.in));

  7.                 PrintWriter outText=new PrintWriter(new FileOutputStream("a.txt"),true);

  8.                 System.out.println("请输入要录入的内容。输入overin或者按Ctrl+C结束录入");

  9.                 String line=null;
  10.                
  11.                 while ((line=keyIn.readLine())!=null)
  12.                 {
  13.                         if("overin".equals(line))
  14.                         break;
  15.                          outText.println(line);
  16.                 }               
  17.                 keyIn.close();   
  18.                 outText.close();
  19.         }
  20. }
复制代码

回复 使用道具 举报
自己好好看看视频
回复 使用道具 举报
君嘘 发表于 2015-4-16 03:58
既然楼主都已经用了BufferedRead读取键盘录入。。。
为何还用Scanner呢。。。
还有……楼主取的变量名看得 ...

谢了。大神,会改进的
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马