Created
January 5, 2017 11:31
-
-
Save gblnovaes/f22b6f3c6e85858266c886ca0ddca1e6 to your computer and use it in GitHub Desktop.
CSV READER
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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