title: How to overwrite a specific chunk in a byte array
body: <p>Given a <strong>bytearray</strong> and a new <strong>bytearray</strong> of which i need to overwrite its content on the original <code>bytearray</code> but <strong>starting</strong> from a specific <strong>position/offset</strong> (A) as shown in the image below(we can say B is the <strong>length</strong> of the new Array).
  Also handling the new <strong>length</strong> if the overwriting <strong>exceeds</strong> the actual length of the original array.</p>
  
  <p>(this is needed for <strong>.WAV</strong> file overwriting in different positions).</p>
  
  <p><img src="https://i.stack.imgur.com/6PkTb.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/An6DK.png" alt="enter image description here"></p>
  
  <p>here is what i have tried so far but no luck.</p>
  
  <pre><code> public byte[] ByteArrayAppender(byte[] firstData, byte[] newData, byte[] remainData, int Position) {
  
      byte[] editedByteArray = new byte[firstData.length + newData.length + remainData.length];
  
  
      System.arraycopy(firstData, 0, editedByteArray, 0, Position);
  
      System.arraycopy(newData, 0, editedByteArray, firstData.length, newData.length);
  
      System.arraycopy(remainData, 0, editedByteArray, newData.length, remainData.length);
  
      return editedByteArray;
  
  }
  </code></pre>