Problem reading file line by line in Java

3

Hello, I'm doing a java program to convert csv files to bib. As the csv file can be 200kb or 2G I decided to read line by line so I do not have problems with low memory. I made the code as follows:

try {
  File file = new File(caminhoAbrirArquivos + nome);
  Scanner inputStream = new Scanner(file);

  linha = inputStream.nextLine();//A primeira linha é o cabeçalho, então descarto
  while (inputStream.hasNextLine()) {
    linha = inputStream.nextLine();

    //Código que realiza a conversão da linha
  }
} catch (FileNotFoundException ex) {
  JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
}

I finished the program, tested it and it worked. But when I ran JAR to use the program it read only the first 30 lines of the file.

When I run the project in Netbeans it reads the entire file and converts, all right, now when I generate the project JAR and run it reads only the first 30 lines of the file and converts only those.

Does anyone know what might be happening?

    
asked by anonymous 30.05.2017 / 15:00

1 answer

1

I was able to solve using the FileReader and BufferedReader objects,

FileReader arq = new FileReader(caminhoAbrirArquivos + nome);
BufferedReader lerArq = new BufferedReader(arq);

linha = lerArq.readLine();//Primeira linha é o cabeçalho, então é descartada
linha = lerArq.readLine();

while (linha != null) {
    //Código que faz a conversão
}
    
17.09.2017 / 01:13