List of usage examples for java.io RandomAccessFile readByte
public final byte readByte() throws IOException
From source file:com.peterbochs.PeterBochsDebugger.java
public String tail2(File file, int lines) { try {//from w w w.j av a 2 s . c om RandomAccessFile fileHandler = new RandomAccessFile(file, "r"); long fileLength = file.length() - 1; StringBuilder sb = new StringBuilder(); int line = 0; for (long filePointer = fileLength; filePointer != -1; filePointer--) { fileHandler.seek(filePointer); int readByte = fileHandler.readByte(); if (readByte == 0xA) { line = line + 1; if (line == lines) { if (filePointer == fileLength) { continue; } else { break; } } } sb.append((char) readByte); } sb.deleteCharAt(sb.length() - 1); String lastLine = sb.reverse().toString(); return lastLine; } catch (Exception e) { return null; } }