So I am relatively new to Android and I am trying to parse a web based CSV document and use two of the values from this document in my app. I have already successfully parsed a CSV document but it only had 1 row. The document I am trying to parse looks like this:
Light,2012-08-20T11:04:42.407301Z,107
Temperature,2012-08-20T11:04:42.407301Z,24
I am trying to get the "107" and the "24" values. Can anyone explain how to do this? This is the code for my current CSV parser class which can successfully parse one line of CSV data.
public class CSVParser {
static InputStream is = null;
private String value;
public String getCSV(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
String line;
while ((line = reader.readLine()) != null) {
String[] RowData = line.split(",");
value = RowData[2];
// do something with "data" and "value"
}
} catch (IOException ex) {
// handle exception
} finally {
try {
is.close();
} catch (IOException e) {
// handle exception
}
}
return value;
}
}