My java code will not transfer my 25mb file – it will stop at 16mb. I have tried changing transferFrom 1 << 24 to 48 & 31 & 8 nothing helped just made it worse. Any idea?
ReadableByteChannel rbc = Channels.newChannel(fileURL.openStream());
FileOutputStream fos = new FileOutputStream(path + fileName);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close();
In case you use
Java7you can use the fancyjava.nio.file.Filesutils to copy.In case you not, you can use the open source utils- e.g. from Apache (search for
FileUtilsin Commons IO).And in case you want to stick arround with your current solution, you can write it like this:
The intention is that you have to read until the end of the stream has been reached. That is why your
transferFromonly downloads a limited amount of data as there is no guarantee that all the data will be transferred in one chunk.