Mega Code Archive

 
Categories / Java / File Input Output
 

Reverse a file with RandomAccessFile

import java.io.RandomAccessFile; class ReverseFile {   public static void main(String args[]) throws Exception {     RandomAccessFile raf = new RandomAccessFile(args[0], "r");     long position = raf.length();     while (position > 0) {       position -= 1;       raf.seek(position);       byte b = raf.readByte();       System.out.print((char) b);     }   } }