I've written a bit of code for downloading an episode of a webcast I do. It gets the URL of the episode and gets the place to save it. However, it only downloads up to 16MB and then automatically cancels. I'm not entirely sure what value to change to increase this. Is it possible, and could someone please point me in the right direction? Thankyou!
The downloading code:
URL url = new URL(episode.getUrl()); ReadableByteChannel rbc = Channels.newChannel(url.openStream()); FileOutputStream fos = new FileOutputStream(episode.getLocalSave()); fos.getChannel().transferFrom(rbc, 0, 1 << 24);
We will use the copy(inputStream, fileOS) method to download a file into the local system. InputStream inputStream = new URL("http://example.com/my-file-path.txt").openStream(); FileOutputStream fileOS = new FileOutputStream("/Users/username/Documents/file_name. txt"); int i = IOUtils. copy(inpuStream, fileOS);
FileOutputStream fileOutputStream = new FileOutputStream(FILE_NAME); FileChannel fileChannel = fileOutputStream. getChannel(); We'll use the transferFrom() method from the ReadableByteChannel class to download the bytes from the given URL to our FileChannel: fileOutputStream.
file = new File(home + "/Downloads/" + "excel" + filename + ". xls"); Runtime. getRuntime(). exec("cmd.exe /C start " + file);
A quick look at the documentation of transferFrom:
public abstract long transferFrom(ReadableByteChannel channel, long position, long count)
WELL.
The value 1<<24 for the count (from the original question) equals 16M
I guess that's the answer to your question :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With