1
I need to handle a 3-line file with the following structure:
nome
data
horário
To read this method I use the following commands:
BufferedReader leitor = new BufferedReader(new FileReader("dados/dados.txt"));
ArrayList<String> dados = new ArrayList<>();
String linha = "";
while((linha = leitor.readLine()) != null){
dados.add(linha);
}
leitor.close();
But at the end of reading, the first line of the file gets corrupted with the value null, when in fact it was to continue with the value of the name field.
How can I do to read the file without corrupting it?
Related: How to read data from txt files using Java?
– user28595
I did exactly what you did and the result came out perfect. It doesn’t seem to be code problem. Tried to make some change?
– Sullyvan Nunes
Thinking it may be a problem in another method that serves to check whether the file is empty or not
– roooooon
in this method I use File = new File("data/data.txt"); only
– roooooon
@Roney If possible post the code of this method.
– stderr