我使用Apache commons FileUtils下载csv文件并保存:
FileUtils.copyURLToFile(new URL("http://www.google.com/finance/historical?q=AAL&startdate=May+14%2C+2017&output=csv"), new File(toFilePrefix + "sadfsd.csv"), 10000, 10000);
我收到以下错误:
java.io.FileNotFoundException: http://www.google.com/finance/historical?q=AAL&startdate=May+14%2C+2017&output=csv
当我在浏览器中运行url时,它可以运行并下载文件。
如果我将网址改为轻微以获得Google的股票,那就可以了:
http://www.google.com/finance/historical?q=GOOG&startdate=May+14%2C+2017&output=csv
整个Stacktrace:
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Mon May 29 19:28:02 PDT 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mysql Connection has been established!
MySQL JDBC Driver has been loaded ...
java.io.FileNotFoundException: http://www.google.com/finance/historical?q=AAL&startdate=Mar+14+2017&output=csv
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1836)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at org.apache.commons.io.FileUtils.copyURLToFile(FileUtils.java:1506)
at com.mycompany.myapp.AppFiles.downloadFiles(AppFiles.java:61)
at com.mycompany.myapp.Main.main(Main.java:8)
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 0.980s
Finished at: Mon May 29 19:28:03 PDT 2017
Final Memory: 5M/245M
------------------------------------------------------------------------
我也尝试使用此问题中的接受答案(使用Java NIO)下载此文件,并显示相同的错误:How to download and save a file from Internet using Java?。