我尝试了两种不同的方法来实现这一目标,第一种:
public class DownloadTest {
public static void main(String[] args) {
URL website;
try {
website = new URL("http://re.zoink.it/067c4cc99A");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("vaca.torrent");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
} catch (Exception e) {
Logger.getLogger(DownloadTest.class.getName()).log(Level.SEVERE, null, e);
}
}
}
第二个:
public class DownloadTest2 {
public static void main(String args[]) throws IOException
{
String Episode = "http://re.zoink.it/067c4cc99A";
String Episode_save = "vaca.torrent";
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(Episode).openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(Episode_save);
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos);
byte data[] = new byte[1024];
int read;
while((read = in.read(data,0,1024))>=0)
{
bout.write(data, 0, read);
}
bout.close();
in.close();
}
}
如果您在浏览器中使用链接,则将显示一个对话框来下载它。或者,如果您尝试:view-source:http : //re.zoink.it/067c4cc99A,则可以看到它是一个实际的torrent文件。
这两种方法都无法使用此链接(我都获得了损坏的文件),但是它们也可用于其他链接,例如http://www.bt-chat.com/download1.php?id=192039&type=torrent
我的问题是如何从第一个下载文件?
请注意,当您使用http时,无法访问此特定URL,而使用https我可以下载,则将“ http://re.zoink.it/067c4cc99A ”更改为“ https://re.zoink.it/067c4cc99A ” 。
收到的响应是压缩文件,请处理响应以将文件解压缩。在给定的情况下,此(response.getEntity()。getContentEncoding())的输出为gzip。我尝试将下载文件的扩展名更改为.zip,但我只能看到其中的种子文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句