0
I am reading a 9 million-line CSV file, and I need to turn each line into an object and store it in a list or buffer to subsequently write to a random access file.
When I try to add the investor objects in the list gives the following error when it reaches 6.462.547 million lines:
How can I get around this mistake?
My reading function (OBS.: The Textfile class can be replaced by the Bufferedreader):
public List<Object> lerDadosCSV(String arquivoCSV, JProgressBar progressBar, JTextField textField, int tipo) {
long indice = 0;
numeroTotalLinhas = numeroTotalLinhas(arquivoCSV) * 2;
try (TextFile textFile = new TextFile(arquivoCSV)) {
DecimalFormat decimalFormat = new DecimalFormat("#,###");
String linha;
List<Object> records = new ArrayList<>();
while ((linha = textFile.readLine()) != null) {
if (indice != 0) {
records.add(tipo == 0 ? montaEstoque(linha.split(";")) : montaInvestidor(linha.split(";")));
}
textField.setText(decimalFormat.format(indice));
progressBar.setValue((int) (indice * 100 / numeroTotalLinhas));
progressBar.setString((int) (indice * 100 / numeroTotalLinhas) + "%");
indice++;
}
return records;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Function montage:
public static Investidor montaInvestidor(String[] splitLinha) {
try {
boolean operou = (splitLinha[10].contains("s|S")) ? true : false,
situacao = (splitLinha[9].contains("a|A")) ? true : false;
Investidor investidor = new Investidor(Integer.parseInt(splitLinha[0]), formataData.parse(splitLinha[1]),
splitLinha[2].trim(), splitLinha[3].trim(), splitLinha[4].trim(), splitLinha[6].trim(),
splitLinha[7].trim(), splitLinha[8].trim(), Integer.parseInt(splitLinha[5]), situacao, operou);
return investidor;
} catch (NumberFormatException | ParseException e) {
e.printStackTrace();
return null;
}
}
I don’t use any framework in this project
– Matheus William