Though it is much more likely you’ll get your data via a json / xml feed, sometimes it becomes necessary in the course of development events to parse a CSV file. If you find yourself in this situation, here’s a nice library that will make the process as painless as can be.
JavaCSV is a library born out of the .Net DataStreams framework. It promises good performance, low resource usage, and near unparalleled scalability (I have yet to test them out on the last claim, but so far I’ve gotten good mileage from the library). Usage is quite simple: just grab the .jar from SourceForge, import it into your project as described in Adding an External .jar to your Project, and read your file via the CsvReader class. Here’s a snippet where I’m reading a file from the /assets folder within an AsyncTask:
protected Integer doInBackground(Void...voids){
// load the .csv file from assets
try {
CsvReader fileReader = new CsvReader(getAssets().open("file.csv"), Charset.defaultCharset());
fileReader.readHeaders();
while(
fileReader.readRecord()){
String unitName = units.get("")
}
} catch (IOException e) {
// TODO Handle Failure to get file
}
return numUnits;
}
Got any libraries you’ve found really useful in your Android development? Let us know in the comments or over at twitter @droidweb!

