Java-Append Data to the End of Existing File

Append Data to the End of Existing File

The following program shows how we could append items to an existing file using the RandomAccessFile class. This program opens the file “data.da” created by previous program and then appends bytes to the end.

Program

sasa

Program Source

import java.io.RandomAccessFile;
import java.io.IOException;

class Javaapp {
    
    public static void main(String[] args) throws IOException {
        
        RandomAccessFile raf = new RandomAccessFile("data.da","rw");
        raf.seek(raf.length());
        
        raf.writeByte(60);
        raf.writeByte(70);
        raf.writeByte(80);
        raf.close();
    }
}

Leave a Comment