public class readFile {
public static void main(String[] args) {
try {
RandomAccessFile rf = new RandomAccessFile("c:\\Analysen.BAK", "r");
long len = rf.length();
long start = rf.getFilePointer();
long nextend = start + len - 1;
String line = null;
rf.seek(nextend);
int c = -1;
while (nextend > start) {
c = rf.read();
if (c == '\n' || c == '\r') {
line = rf.readLine();
if (line == null || line.trim().equals("")) {
nextend--;
rf.seek(nextend);
continue;
}
break;
}
nextend--;
rf.seek(nextend);
if (nextend == 0) {// 当文件指针退至文件开始处,输出第一行
line = rf.readLine();
}
}
// 处理函数
System.out.print(line);
} catch (Exception e) {
System.out.println("Error handling a client: " + e);
}
}
}