Is there a way to add data into a RandomAccessFile using seek(long) without writing over the data at that position and beyond? For example:
public static void main(String[] args) throws Exception {
RandomAccessFile raf = new RandomAccessFile("test.txt", "rw");
raf.writeBytes("Hello, World!");
seek(2);
raf.writeBytes("Goodbye, World!");
raf.close();
}
Using that the file would read
HeGoodbye, World!
Is there a way to make it
HeGoodbye, World!llo, World
instead?
The way I was thinking isn't practical enough to use as it involved reading all the data from the desired position to the end and then writing it back into the file after the write("Goodbye, World!"); but in a large file that's not really possible.
So any ideas would be appreciated!