package de.uhilger.avdirektor; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.logging.Logger; /** * * @author ulrich */ public class OMXLogLeser { private static final Logger logger = Logger.getLogger(OMXLogLeser.class.getName()); public String lesen(File logfile) throws FileNotFoundException, IOException { InputStream is = new FileInputStream(logfile); BufferedReader r = new BufferedReader(new InputStreamReader(is)); String firstLine = r.readLine(); String lastLine = ""; if(firstLine != null) { long size = logfile.length(); long pos = size - (long) 1000; logger.info("Size: " + size + ", Pos: " + pos); // 2.341.930 Bytes long skipped = r.skip(pos); logger.info("skipped: " + skipped); String line = r.readLine(); while(line != null) { lastLine = line; logger.info(lastLine); line = r.readLine(); } } r.close(); is.close(); StringBuilder sb = new StringBuilder(); sb.append("\r\n---"); sb.append("\r\nfirst line:\r\n"); sb.append(firstLine); sb.append("\r\n\r\nlastLine\r\n"); sb.append(lastLine); String lines = sb.toString(); logger.info(lines); return lines; } }