I have a simple function to read a file, however it only reads lines, and I would like it before reading the contents of each lines, I already had the total value of rows in the file.
try {
FileReader leitor = new FileReader("config.txt");
//file to reade
BufferedReader buffer = new BufferedReader(leitor, 2 * 1024 * 1024);
String linha = buffer.readLine();
while (linha != null) {
//I want to do an "if" here to get the value of the last line of the file and save in a variable.
System.out.print(linha + "\n");
linha = buffer.readLine();
Thread.sleep(1000);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (
IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
Thanks.