如何覆盖Java中特定位置的文件内容?
How to overwrite file content at specific position in Java?
我正在处理大文件,我想在特定位置覆盖内容文件,如下所示:
helloworld123456
覆盖新内容 "internet" 第 6 个字
hellointernet456
非常感谢
编辑:
RandomAccessFile 可以直接查找和写入文件及其工作
randomAccessFile.seek(5);
randomAccessFile.write("internet".getBytes());
正如这里的回答:
You can't insert data into a file. You can overwrite data at a specific location with RandomAccessFile. However an insert requires changing all of the data after it.
how to write content in a Specific position in a File
我正在处理大文件,我想在特定位置覆盖内容文件,如下所示:
helloworld123456
覆盖新内容 "internet" 第 6 个字
hellointernet456
非常感谢
编辑: RandomAccessFile 可以直接查找和写入文件及其工作
randomAccessFile.seek(5);
randomAccessFile.write("internet".getBytes());
正如这里的回答:
You can't insert data into a file. You can overwrite data at a specific location with RandomAccessFile. However an insert requires changing all of the data after it.
how to write content in a Specific position in a File