title: Why am I getting an index out of bounds when I try to read certain bytes from a file?
body: <p>Can anyone figure out why I'm getting an index out of bounds exception here? I can read in the first lot of data but when I try and loop this again it errors. Im also getting an 'assigned value is never used' error on the is.read(readBytes, offset, length); part of this too.</p>
  
  <pre><code>InetAddress address = packet.getAddress();
  
  int port = packet.getPort();
  
  RRQ RRQ = new RRQ();
  
  int offset = 0;
  int length = 512;
  int block = 0;
  
  byte[] readBytes = new byte[512];
  
  File file = new File(filename);
  FileInputStream is = new FileInputStream(file);
  
  int fileBytes = is.read(readBytes, offset, length);
  
  DatagramPacket outPacket = RRQ.doRRQ(readBytes, block, address, port);
  socket.send(outPacket);
  
  block++;
  
  if (fileBytes != -1)
  {                   
      socket.receive(packet);
  
      offset = offset + fileBytes;
  
      System.out.println(offset);
  
      Exceptions here:fileBytes = is.read(readBytes, offset, length);
  
      outPacket = RRQ.doRRQ(readBytes, block, address, port);
      socket.send(outPacket);
      block++;
  }
  </code></pre>