Java .torrent文件下载 [英] Java .torrent file download

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

问题描述

我想从此链接下载一个.torrent文件
http://torrage.com /torrent/13764753227BCBE3E8E82C058A7D5CE2BDDF9857.torrent
这样做我使用这个代码

I want to download a .torrent file from this link http://torrage.com/torrent/13764753227BCBE3E8E82C058A7D5CE2BDDF9857.torrent to do this I use this code

URL website = new URL(link);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
File f = new File(path+"t2.torrent");
FileOutputStream fos = new FileOutputStream(f);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();

现在,当我在utorrent中打开它时,我收到以下消息:无法加载t2.torrent :torrent不是一个有效的bencoding!

Now, when I open it in utorrent i get this message : Unable to load "t2.torrent": torrent is not a valid bencoding!

从我在互联网上阅读我学习,这个文件有一个特殊的编码。
什么是propper方式下载end编码这种文件。
谢谢!

From what I read on internet I learnd that this files have a special encoding. What is the propper way to download end encode this kind of file. Thanks!

推荐答案

torrent文件损坏的原因是您正在下载的Web服务器提供以压缩(gzip压缩)格式。您可以使用以下代码将其解压缩到Java中:

The reason the torrent file becomes corrupted is that the web server you are downloading it from provides it in compressed (gzipped) format. You can unzip it in Java using the following code:

URL url = new URL(link);
try (InputStream is = new GZIPInputStream(url.openStream())) {
  Files.copy(is, Paths.get(path + "t2.torrent"));
}

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

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