// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.RandomAccessFile;

public class LastLine {
    public static String readLastLineSupButSlow(String fnm) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(fnm));
        String lastline = null;
        String line;
        while((line = br.readLine()) != null) {
            lastline = line;
        }
        br.close();
        return lastline;
    }
    public static String readLastLineUnSup(String fnm) throws IOException {
        RandomAccessFile raf = new RandomAccessFile(fnm, "r");
        String res = "";
        long ix = raf.length() - 1;
        for(;;) {
            raf.seek(ix);
            int c = raf.read();
            if(c == '\r' || c == '\n') break;
            res = (char)c + res;
            ix--;    
        }
        raf.close();
        return res;
    }
    public static void main(String[] args) throws Exception {
        System.out.println(readLastLineSupButSlow("C:\\z.txt"));
        System.out.println(readLastLineUnSup("C:\\z.txt"));
    }
}
