home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / Java++ / VJ / SAMPLES / JAVANOW / CHAP10 / FILEIO / FILEIO.JAVA < prev    next >
Encoding:
Java Source  |  1996-08-23  |  1.2 KB  |  42 lines

  1. import java.io.*;
  2.  
  3. public class FileIO
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         try
  8.         {
  9.             // open args[0] for input
  10.             FileInputStream in = new FileInputStream(args[0]);
  11.  
  12.             // add buffering to that InputStream
  13.             BufferedInputStream bin = 
  14.                                   new BufferedInputStream(in);
  15.  
  16.             // open args[1] for output and add buffering to
  17.             // it as well
  18.             FileOutputStream out = new FileOutputStream(args[1]);
  19.             BufferedOutputStream bout = 
  20.                                   new BufferedOutputStream(out);
  21.  
  22.             // now read as long as there is something to read
  23.             byte bArray[] = new byte[256];
  24.             int nBytesRead;
  25.             while(bin.available() > 0)
  26.             {
  27.                // read up a block - remember how many bytes read
  28.                nBytesRead = bin.read(bArray);
  29.  
  30.                // write that many bytes back out starting
  31.                // at offset 0 in the array
  32.                bout.write(bArray, 0, nBytesRead);
  33.             }
  34.             bout.flush();
  35.         }
  36.         catch(IOException ioe)
  37.         {
  38.             System.out.println(ioe.toString());
  39.         }
  40.     }
  41. }
  42.