【例7-6】源程序Bwriter.java,從鍵盤鍵入一系列字符串,寫入到某磁盤文件中。

import java.io.*;

public class Bwriter

{

    public static void main(String args[])   throws Exception

    {

     InputStreamReader i=new InpytStreamReader(System.in);

     BufferedReader b=new BufferedReader(i);

     FileWriter w=new FileWriter("file1.txt");

     BufferedWriter w=new BufferedWriter(f);

     String s;

     while(true)

       {

         System.out.print("input a string:");

         System.out.flush();

             s=b.readLine();

             if(s.length()==0)

             break;                           //如果用戶直接回車,代表結束

             w.write(s);

             w.newLine();

        }

     w.close( );

     }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章