title: FileOutputStream.writeBytes out of bounds
body: <p>My Program reads a file into a byte array and then tries to carve out a bmp image from the file. The problem is I am getting an out of bounds error. </p>
  
  <pre><code>{
      public static void main( String[] args )
  {
      FileInputStream fileInputStream=null;
  
      File file = new File("C:/thumbcache_32.db");
  
      byte[] bFile = new byte[(int) file.length()];
  
      System.out.println("Byte array size: " + file.length());
  
      try {
          //convert file into array of bytes
      fileInputStream = new FileInputStream(file);
      fileInputStream.read(bFile);
  
      fileInputStream.close();
  
  
      //convert array of bytes into file
      FileOutputStream fileOuputStream = 
                new FileOutputStream("C:/Users/zak/Desktop/thumb final/Carved_image.bmp"); 
      fileOuputStream.write(bFile,1573278,1577427);
      fileOuputStream.close();
  
      System.out.println("Done");
      }catch(Exception e){
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The size of the byte array one the file is loaded into is "3145728"</p>
  
  <p>and I am trying to copy bytes "1573278" to "1577427". As you can see these bytes are within bounds of the byte array so im unsure why  I am getting this error</p>
  
  <p><strong>output of program  when run</strong></p>
  
  <pre><code>Byte array size: 3145728
  java.lang.IndexOutOfBoundsException
  at java.io.FileOutputStream.writeBytes(Native Method)
  at java.io.FileOutputStream.write(Unknown Source)
  at Byte_copy.main(Byte_copy.java:28)
  </code></pre>