无法使用Java

时间:2016-10-18 20:35:17

标签: java

我正在尝试从SEC.gov下载文件,但以下代码无法下载该文件。使用此代码下载的所有文件均为1 KB。

URL Url = null;

try {
    Url= new URL("http://www.sec.gov/Archives/edgar/data/769397/000076939716000079/0000769397-16-000079-xbrl.zip");

} catch (MalformedURLException e) {

    e.printStackTrace();
}

String fullPathFileName = "D:\\0000769397-16-000079-xbrl.zip";

File destinationFile = new File(fullPathFileName);

try {
    FileUtils.copyURLToFile(Url, destinationFile);

} catch (IOException e) {

    e.printStackTrace();

}

如果我使用相同的代码从其他网站下载,它可以正常工作。我还尝试了连接超时和读取超时的copuURLToFile方法。

1 个答案:

答案 0 :(得分:0)

FileUtils.copyURLToFile()的问题在于它没有向您提供有关其所做工作的任何信息。从命令行尝试wget实用程序:

wget http://www.sec.gov/Archives/edgar/data/769397/000076939716000079/0000769397-16-000079-xbrl.zip
--2016-10-18 21:47:31--  http://www.sec.gov/Archives/edgar/data/769397/000076939716000079/0000769397-16-000079-xbrl.zip
Resolving www.sec.gov... 104.82.85.98
Connecting to www.sec.gov|104.82.85.98|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.sec.gov/Archives/edgar/data/769397/000076939716000079/0000769397-16-000079-xbrl.zip [following]
--2016-10-18 21:47:32--  https://www.sec.gov/Archives/edgar/data/769397/000076939716000079/0000769397-16-000079-xbrl.zip
Connecting to www.sec.gov|104.82.85.98|:443... connected.
ERROR: cannot verify www.sec.gov's certificate, issued by `/C=US/O=GeoTrust Inc./CN=GeoTrust SSL CA - G3':
  Unable to locally verify the issuer's authority.
To connect to www.sec.gov insecurely, use `--no-check-certificate'.
Unable to establish SSL connection.

您可能会收到类似的错误消息。尝试在记事本中打开1KB文件。