Downloading CSV files programmatically using java

Scenario: the website I use to study stock data has a link on the page to export the data to a spreadsheet The format of the URL displayed when hovering over the export link is http://www.stocksite.com/historical/export.php?symbol=C.

Question: instead, I want to manually access each inventory page. I want to complete the task automatically From Java, how can I programmatically use the stock code to call the website and save the exported CSV file? URL and urlconnection are similar, which is an obvious starting point, but I'm not sure where to start

Solution

InputStream input = new URL("http://example.com/file.csv").openStream();

Then you can send it to any decent Java CSV parser API Almost any one can input the taste of InputStream or reader If necessary, you can easily decorate the InputStream as a reader using inputstreamreader, and then you can provide it to the CSV parser

Reader reader = new InputStreamReader(input,"UTF-8");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>