package io;
import java.io.RandomAccessFile;
public class RandomAccessFileTest {
public static void main(String[] args)throws Exception {
printFileInReverseOrder();
}
private static void printFileInReverseOrder()throws Exception{
RandomAccessFile randomAccessFile = new RandomAccessFile("D:/Projects/JDK/src/io/info.txt","r");
long endIndex = randomAccessFile.length();
while(endIndex>=0){
randomAccessFile.seek(endIndex);
char c = (char) randomAccessFile.read();
if(c=='\n'){
System.out.println(randomAccessFile.readLine());
}
if(endIndex==0){
randomAccessFile.seek(0);
System.out.println(randomAccessFile.readLine());
}
endIndex--;
}
randomAccessFile.close();
}
}