在java中下载一个大文件

时间:2016-07-05 09:07:34

标签: java url fileutils

这是我从网页下载文件并将其保存在路径中的代码:

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.apache.commons.io.FileUtils;

public class Demo2 {
    public static void main(String...args){

        try {
            URL url = new URL("ftp://ftp.fu-berlin.de/pub/misc/movies/database/crazy-credits.list.gz");
            FileUtils.copyURLToFile(url, new File("D:\\imdb\\credits.list.gz"));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

我的连接超时异常:

java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at sun.net.ftp.impl.FtpClient.doConnect(FtpClient.java:958)
    at sun.net.ftp.impl.FtpClient.tryConnect(FtpClient.java:918)
    at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1013)
    at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:999)
    at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:294)
    at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:393)
    at java.net.URL.openStream(URL.java:1037)
    at org.apache.commons.io.FileUtils.copyURLToFile(FileUtils.java:1460)
    at plotgz.Demo2.main(Demo2.java:14)

我无法弄清楚究竟是什么问题,因为它适用于其他网址:

  

http://www.vtuplanet.com/d.php?type=papers&file=B.E+%28Engineering%29%2FComputer+Science+%28CSE%29%2FSem+5%2FDBMS%2FDBMS+Notes+%5B2010%5D+%28SJBIT%29.pdf

有人可以帮我这个吗?提前谢谢!!

0 个答案:

没有答案