Skip to content

Instantly share code, notes, and snippets.

@gblnovaes
Created January 5, 2017 11:31
Show Gist options
  • Save gblnovaes/f22b6f3c6e85858266c886ca0ddca1e6 to your computer and use it in GitHub Desktop.
Save gblnovaes/f22b6f3c6e85858266c886ca0ddca1e6 to your computer and use it in GitHub Desktop.
CSV READER
public class CSVFile {
InputStream inputStream;
Context context;
List resultCSVlist = new ArrayList();
public CSVFile(InputStream inputStream, Context context) {
this.inputStream = inputStream;
this.context = context;
}
public List readCSV() {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
try {
String csvLine;
while ((csvLine = reader.readLine()) != null) {
String[] row = csvLine.split(",");
resultCSVlist.add(row);
}
} catch (IOException e) {
throw new RuntimeException("Erro ao ler CSV arquivo: " + e);
}finally {
try {
inputStream.close();
}
catch (IOException e) {
throw new RuntimeException("Erro ao fechar input stream "+ e);
}
}
return resultCSVlist;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment