io - how to read last line in a text file using java -


this question has answer here:

i making log , want read last line of log.txt file, i'm having trouble getting bufferedreader stop once last line read.

here's code:

try {     string scurrentline;      br = new bufferedreader(new filereader("c:\\testing.txt"));      while ((scurrentline = br.readline()) != null) {         system.out.println(scurrentline);     } } catch (ioexception e) {     e.printstacktrace(); } {     try {         if (br != null)br.close();     } catch (ioexception ex) {         ex.printstacktrace();     } } 

here's solution.

in code, create auxiliary variable called lastline , reinitialize current line so:

    string lastline = "";      while ((scurrentline = br.readline()) != null)      {         system.out.println(scurrentline);         lastline = scurrentline;     } 

Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -