How does java purge existing content before each write without closing the stream?

scene description

If the

cycle processes some data and fails to process one, record the current offset to meta.txt , so that after the program exception stops, the last offset is read after the program is restarted next time, and the processing continues instead of starting all over again.

if you re-create FileOutputStream each time you want to write, you can empty the existing content, but with such a large number of new ones, close the stream. Personally, it feels like it consumes a lot of resources.

so is there any way to achieve my needs with very little expenditure?

in addition,
it occurred to me that before each write, delete the existing file and then create a new file, but still use the existing stream.
I don"t know if this is feasible?
if so, is it less expensive than each new stream?

Apr.05,2021

flush ()

Menu