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

  1.  
  2. import java.io.*;
  3.  
  4. public class BufferedWriteDataStream
  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.         double[] allDoubles = {1.1,3.1,5.1,7.1,9.1,11.1,13.1,15.1,17.1,19.1,21.1,23.1,25.1,27.1,29.1};
  11. try
  12.         {
  13.             //declare a stream and attach it to a file
  14.             FileOutputStream ofile = new FileOutputStream("bufDouble.dat");
  15.  
  16.             //declare a buffer and attach it to a stream
  17.             BufferedOutputStream bufStream = new BufferedOutputStream(ofile);
  18.  
  19.             //declare a data stream and assign it to a buffer
  20.             DataOutputStream datStream = new DataOutputStream(bufStream);
  21.  
  22.             for (int i=0; i < allDoubles.length; i++)
  23.                 //write to the datastream
  24.                 datStream.writeDouble(allDoubles[i]);
  25.             datStream.close();
  26.         } catch (IOException e)// handle any errors
  27.             {
  28.                 System.out.println("Error - " + e.toString());
  29.             }//catch
  30.     }//main
  31. }//BufferedWriteDataStream
  32.  
  33.  
  34.  
  35.