Hello. There is, for example, such url http://quote.yahoo.com/d/quotes.csv?s=AAPL&f=sl1d1t1c1ohgv&e=.csv if you enter it into a browser, then the file is downloaded in csv format. Everything is working fine. I'm trying to programmatically get the contents of this file into a string variable:

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class MyStockQuote { public static void main(String[] args) { URL url = null; URLConnection urlCon = null; InputStreamReader inStream = null; BufferedReader buff = null; String csvString; try{ url = new URL("http://quote.yahoo.com/d/quotes.csv?s=AAPL&f=sl1d1t1c1ohgv&e=.csv"); urlCon = url.openConnection(); inStream = new InputStreamReader(urlCon.getInputStream()); buff = new BufferedReader(inStream); csvString =buff.readLine(); System.out.println(csvString); }catch(MalformedURLException e){ System.out.println("Please check the spelling of " + "the URL: " + e.toString() ); } catch(IOException e1){ System.out.println("Can't read from the Internet: " + e1.toString() ); } finally{ try{ inStream.close(); buff.close(); }catch(Exception e){ System.out.println("StockQuote: can't close streams" + e.getMessage()); } } } } 

but the result is <HTML> What am I doing wrong?

    1 answer 1

    I figured it out myself. The document changed the url. If in a cycle to bring the entire document, then there is a message that the file has moved and a new url is given.