The javadoc for FileChannel.transferFrom
says this:
"An attempt is made to read up to count bytes from the source channel and write them to this channel's file starting at the given position. An invocation of this method may or may not transfer all of the requested bytes; whether or not it does so depends upon the natures and states of the channels. Fewer than the requested number of bytes will be transferred if the source channel has fewer than count bytes remaining, or if the source channel is non-blocking and has fewer than count bytes immediately available in its input buffer."
In this case, the source channel is a non-blocking channel, and therefore the transferFrom
method is not guaranteed to transfer the entire content in one go.
As @EJP says, you need to put the transferFrom
call into a loop, etcetera.
But I think you would be better off using the InputStream
and OutputStream
APIs directly, reading into and writing out of a byte[]
... in a loop.