title: Copying a file byte-by-byte using DataInputStream stops before completion
body: <p>I have written  the following program in java to copy file using DataInput\Output Stream.</p>
  
  <pre><code>import java.io.*;
  public class FileCopier {
  
      public static void main(String args[]) throws Exception
      {
          File file = new File("/home/Sample.mkv");
          File copy = new File("/home/Copy_of_Sample.mkv");
          if(copy.exists())
          {
              copy.delete();
          }
          copy.createNewFile();
          DataInputStream din = new DataInputStream(new FileInputStream(file));
          DataOutputStream dout = new DataOutputStream(new FileOutputStream(copy));
          byte c;
          c = 1;
          long time = System.currentTimeMillis();
          while(c!=-1)
          {
              c =  (byte) din.read();
              dout.write(c);
          }
  
          time = System.currentTimeMillis() - time;
          System.out.println(time);
      }
  }
  </code></pre>
  
  <p>However i am not getting th expected result. As i know read() method DataInputStream  reads next byte from input stream and converts it into int. Here i am converting that again into bytes and writing that byte to another file, but still this is not working as expected. The original file which i am trying to copy is of size 8.5 MB while the copied one has the size of 5.3 MB only.</p>
  
  <p>Plz help me understand why this is happening.</p>
  
  <p>Thanks in advance,
  Nishant </p>