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

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -