output operations write bytes starting at the file pointer and advance
the file pointer past the bytes written
RandomAccessFile treats the file as a byte array. Its behavior of modifying the value of a certain position is to write the value of the i-th position as a new value, and then point the pointer to the next element.
As you can see, this class will not help you complete all the remaining value shifting functions. So if you need to complete the "insert" function, you need to read the subsequent contents of the array yourself and write them to the file in order.
stackoverflow reference:
Inserting text in middle using RandomAccessFile removes some text after that
The answer is no.
RandomAccessFile
This sentence
RandomAccessFile treats the file as a byte array. Its behavior of modifying the value of a certain position is to write the value of the i-th position as a new value, and then point the pointer to the next element.
As you can see, this class will not help you complete all the remaining value shifting functions. So if you need to complete the "insert" function, you need to read the subsequent contents of the array yourself and write them to the file in order.
stackoverflow reference: