io - Java: Replace part of file without writing the entire file again -


is possible replace part of files content, without rewriting entire file disk. have large file of several gigabytes, how replace bytes from, lets position 100 200 without rewriting entire file?

as added bonus, need solution not use features never java 1.4.

if you're positive you're going writing same number of bytes, can use randomaccessfile accomplish (available since java 1.0). open file, seek wherever need be, , overwrite bytes whatever new data is.

randomaccessfile f = new randomaccessfile(new file("c:\\test\\huge.txt"), "rw"); f.seek(100); // seek ahead f.write("here new stuff".getbytes()) 

you can read file @ arbitrary points in same fashion, in case don't know how data need replace (e.g. can pad/truncate whatever you're writing avoid doing awful accident).


Comments

Popular posts from this blog

vue.js - Create hooks for automated testing -

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

serial port - hub4com OVERRUN Error -