使用Java下载文件 [英] Downloading files with Java

查看:100
本文介绍了使用Java下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些代码来下载我做的网络直播。它获取剧集的URL并获取保存它的位置。但是,它最多只下载16MB然后自动取消。我不完全确定要改变什么值以增加它。是否有可能,有人可以指出我正确的方向吗?谢谢!

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!

下载代码:

    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);


推荐答案

快速查看transferFrom的文档:

A quick look at the documentation of transferFrom:

public abstract long transferFrom(ReadableByteChannel channel, long position, long count)

WELL。

计数值(<< 24)(来自原始问题)等于16M

The value 1<<24 for the count (from the original question) equals 16M

我想这就是你问题的答案: - )

I guess that's the answer to your question :-)

这篇关于使用Java下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆