Java. Update (rewrite) shared file

56 Views Asked by At

I have a shared file with access through network. This file has direct link and being downloaded almost permanently, so it's always locked for reading. But sometimes I need to update this file with new data using java code, but I can't do it.
I want to know ways, principles, best practices on how to achieve this. Maybe I should use a controller instead of direct link to put some logic to create a copy for reading purposes, but copy needs to be updated as well while being readed. Connection interrupting is undesirable. Any ideas please???

1

There are 1 best solutions below

3
On

Hi @MichaelD why dont you use the mv command ? You could create the new file as say new.tmp however you please then use "mv new.tmp original.txt" to update the file, mv is atomic so this should work as you expect