Using java Syntax Highlighting
- // reads your file
- BufferedReader in = new BufferedReader(your csv flie source here);
- // creates a new string to put your data in
- String reader = "";
- // looks for the next line that has data
- while ((reader = in.readLine()) != null){
- // tells the reader to slipt the data when it comes to commas
- String[] RowData = reader.split(",");
- // create new strings with your split data in them
- date = RowData[0];
- value = RowData[1];
- // this is where I append the data to my database
- ContentValues values = new ContentValues();
- values.put(CsvProvider.DATE, date);
- values.put(CsvProvider.VALUE, value);
- getContentResolver().insert(CsvProvider.CONTENT_URI, values);
- }
- // ends the loop
- in.close();
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
My CSV file has no titles and only has 2 column but more than two columns should not be a problem. Just remember to specify what is splitting your columns and for each column add another RowData[#](you have to start with 0). You want to make sure whatever you are going to do with each line is done before you call in.close(). I am using a content provider but you can really do whatever you want with the data like append it to a String[] or whatever else.
While I am using an input stream you can point the BufferedReader to wherever you want. As long as the BufferedReader can read it then it will work.

