title: Can I make the size of a byte array dynamic?
body: <p>I'm using a byte array with the write() method of <code>OutputStream</code> to store the data into a file.
  For that, I'm initiating the byte array with a predefined size. But I don't want it to take up so much space for every <code>InputStream</code> whose size could be much lower than the size of the array. Is it possible to somehow make the array dynamic so that it adjusts its size depending on the size of the <code>InputStream</code>?
  I have something like this in my code:</p>
  
  <pre><code>byte[] b = new byte[20000];
  int length;                 
  while ((length = in.read(b))!= -1) {
      //writing it to a file
      op.write(b, 0, length);
      k++;
  }
  
  in.close();
  op.close();
  </code></pre>
  
  <p>Here, <code>in</code> is the <code>InputStream</code> object and <code>op</code> is the <code>FileOutputStream</code> object.
  I've tried using ArrayLists, but there is no direct method of <code>FileOutputStream</code> to write data into an ArrayList, it only accepts <code>byte[]</code>.</p>