tags:

views:

30

answers:

1

I am creating a webApp that will download some data from Yahoo Finance into a CSV file and then (hopefully) be able to then read the created CSV data into a HTML table.

I have successfully got the program to connect to the Yahoo feed and then download that data into a CSV file and would not like to use the data from the file into a table.

Below is the code i used to create the CSV file:

    String ticker = request.getParameter("stockSym");
    URL url = new URL("http://finance.yahoo.com/d/quotes.csv?s=" + ticker + "&f=abc");
    InputStream in = url.openStream();
    BufferedInputStream bufIn = new BufferedInputStream(in);

    File f=new File("stockInfo.csv");
    FileOutputStream fop=new FileOutputStream(f);

    for (;;)
    {
        int data = bufIn.read();

        // Check for EOF
        if (data == -1)
            break;
        else
            fop.write((char) data);
    }
    fop.flush();
    fop.close();

Are there any JSP programmers who would know how to open and then parse a CSV file into a table or would know of any good links to tutorials on how to accomplish this task?

Thanks.

+1  A: 

Do not write the CSV parsing code yourself, use one of the many available libraries.

They can handle tricky things like line breaks, quotes, embedded commas and so on.

Thilo