这是我从网页下载文件并将其保存在路径中的代码:
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)
我无法弄清楚究竟是什么问题,因为它适用于其他网址:
有人可以帮我这个吗?提前谢谢!!