I'm trying to get a csv file from http://download.finance.yahoo.com/d/quotes.csv?s=msft&f=sl1p2 then parse it so that I can get the price and the price changed into an object that sets both properties. Is there a way that I can do this with the android libraries?
Edit: Here's the current state of the union (not working):
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(uri);
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = null;
while ((line = reader.readLine()) != null){
result += line + "\n";
String[] RowData = result.split("\n");
String name = RowData[0];
String price = RowData[1];
String change = RowData[2];
stock.setPrice(Double.parseDouble(price));
stock.setTicker(name);
stock.setChange(change);
}
Try something like this:
Hope this helps.
A better CSV parser handles quoted fields
Usage
Sample data used
ID,Name
1,Test Item 1
"2","Test Item 2"
"3","Test , Item 3"
4,Test Item 4
For the first part:
For the second part, Harry is right, just follow his code, or use some libraries: http://commons.apache.org/sandbox/csv/