Home  >  Q&A  >  body text

java RandomAccessFile 覆盖数据

迷茫迷茫2714 days ago1125

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 14:24:26

    The answer is no.
    RandomAccessFile

    This sentence

    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:

    1. Inserting text in middle using RandomAccessFile removes some text after that

    reply
    0
  • Cancelreply