home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / javafile / ch10 / BufferedWriteCharStream.java < prev    next >
Encoding:
Java Source  |  1998-12-14  |  933 b   |  31 lines

  1.  
  2. import java.io.*;
  3.  
  4. public class BufferedWriteCharStream
  5. {
  6.     // This program runs as an application
  7.     public static void main(String[] arguments)
  8.     {
  9.         //Create an array of data to print
  10.         char[] allChars = {'H','e','l','l','o',' ','W','o','r','l','d','\n'};
  11. try
  12.         {
  13.             //declare a stream and attach it to a file
  14.             FileWriter ofile = new FileWriter("bufChar.dat");
  15.  
  16.             //declare a BufferedWriter - attach it to a stream
  17.             BufferedWriter bufStream = new BufferedWriter(ofile);
  18.  
  19.             for (int i=0; i < allChars.length; i++)
  20.                 //write to the char stream
  21.                 bufStream.write(allChars[i]);
  22.             bufStream.close();
  23.         } catch (IOException e)// handle any errors
  24.             {
  25.                 System.out.println("Error - " + e.toString());
  26.             }//catch
  27.     }//main
  28. }//BufferedWriteCharStream
  29.  
  30.  
  31.