3
I want to read a txt file recording each line of the file in variables of type String, (I use to save some data, of a basic program that I am doing) I thought of something like this
try {
FileReader fr = new FileReader("C:\\Users\\lucas\\Desktop\\teste.txt");
BufferedReader br = new BufferedReader (fr);
String linha1 = br.readLine();// Uma da variaveis
// String linha2 = (?) // Como pego a segunda linha do txt e salvo aqui ?
// String linha3 = (?)
while (linha != null){
SetFirst(linha);// Funcao do objeto o qual estao os dados guardados
linha=br.readLine();
}
System.out.println("Exiting...");
br.close();
fr.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,e.getMessage());
}
And who doubts about the code?
– user28595
I would like to know how to store the other lines of the text file in different variables, if possible.
– Lucas Gregorio
List<String> linhas = Files.readAllLines(Paths.get("meuarquivo.txt"));
– Renan Gomes
Jeez, very complex, but vlw
– Lucas Gregorio
Has any response helped solve the problem and can address similar questions from other users? If so, make sure to mark the answer as accepted. To do this just click on the left side of it (below the indicator of up and down votes).
– Sorack