// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.File;
import java.io.RandomAccessFile;

public class FileFun {
    public static void main(String[] args) throws Exception {
        File f = new File("C:\\z.txt");
        long len = f.length();
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        raf.seek(len - 1);
        int b = raf.read();
        System.out.println("Last byte was " + b);
        raf.setLength(len - 1);
        System.out.println("Last byte truncated");
        raf.close();
    }
}
