public static void copyStream(final File aFile, final OutputStream aOutStream) throws IOException {
        final FileInputStream input = new FileInputStream(aFile);
        final FileChannel channel = input.getChannel();
        final byte[] buffer = new byte[256 * 1024];
        final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);

        try {
            for (int length = 0; (length = channel.read(byteBuffer)) != -1;) {
                aOutStream.write(buffer, 0, length);
                byteBuffer.clear();
            }
        } finally {
            input.close();
        }
    }
public static void copyStream ( final File aFile , final OutputStream aOutStream ) throws IOException { final FileInputStream input = new FileInputStream ( aFile ) ; final FileChannel channel = input . getChannel ( ) ; final byte [ ] buffer = new byte [ 256 * 1024 ] ; final ByteBuffer byteBuffer = ByteBuffer . wrap ( buffer ) ; try { for ( int length = 0 ; ( length = channel . read ( byteBuffer ) ) != - 1 ; ) { aOutStream . write ( buffer , 0 , length ) ; byteBuffer . clear ( ) ; } } finally { input . close ( ) ; } }
Writes a file to an output stream. You're responsible for closing the <code>OutputStream</code>; the input
stream is closed for you since just a <code>File</code> was passed in.

@param aFile A file from which to read
@param aOutStream An output stream to which to write
@throws IOException If there is a problem reading or writing