title: Is there a better way to write the full contents of a file to an OutputStream?
body: <p>When I want to write the full contents of a file into an <code>OutputStream</code>, I usually allocate a buffer as a <code>byte[]</code>, then make a <code>for</code> loop to <code>read</code> data from the file's <code>InputStream</code> into the buffer and write the buffer contents into the <code>OutputStream</code>, until the <code>InputStream</code> has no more bytes available.</p>
  
  <p>This seems rather clumsy to me. Is there a better way to do this?</p>
  
  <p>Also, I am always unsure about the buffer size. Usually, I am allocating 1024 bytes, because it just feels good. Is there a better way to determine a reasonable buffer size?</p>
  
  <p>In my current case, I want to copy the full contents of a file into the output stream that writes the contents of an HTTP response. So, this is not a question about how to copy files on the file system.</p>