title: How to copy files in JAVA by bufferedInputStream and bufferedOutputStream?
body: <p>I would like to use <code>bufferedInputStream</code> and <code>bufferedOutputStream</code> to copy large binary files from source file to destination file.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>   byte[] buffer = new byte[1000];        
      try {
          FileInputStream fis = new FileInputStream(args[0]);
          BufferedInputStream bis = new BufferedInputStream(fis);
  
          FileOutputStream fos = new FileOutputStream(args[1]);
          BufferedOutputStream bos = new BufferedOutputStream(fos);
  
          int numBytes;
          while ((numBytes = bis.read(buffer))!= -1)
          {
              bos.write(buffer);
          }
          //bos.flush();
          //bos.write("\u001a");
  
          System.out.println(args[0]+ " is successfully copied to "+args[1]);
  
          bis.close();
          bos.close();
      } catch (IOException e)
      {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>I can successfully copy but then I use </p>
  
  <pre><code>cmp src dest
  </code></pre>
  
  <p>in the command line to compare two files. 
  The error message </p>
  
  <blockquote>
    <p>cmp: EOF on files</p>
  </blockquote>
  
  <p>appears. May I know where I was wrong?</p>