If there is ever a need to write bytes to a specific location to an existing file, here is an example of how to use the RandomAccessFile and FileChannel Java classes to do so:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
/**
* Will write bytes to the beginning of an existing file.
*
* @author Ryan Chapin
*/
public class RandomAccessFileTest {
public static void main(String[] args) {
// Generate input string and the → Continue reading “Java: How To Use RandomAccessFile and FileChannel to Write to a Specific Location in a File”