0

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???

MichaelD
  • 1
  • 1

1 Answers1

0

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

Jev Prentice
  • 129
  • 4
  • I update file through code. First I gather data and then put into file. I will be unable to update file until it's unlocked. And as I said it's almost always locked – MichaelD Apr 23 '20 at 10:52
  • Can you not read the locked file with your program, perform your processing and create a new tmp file then replace the existing file (the one you want to update) with the tmp file using mv. By doing this the file is not "updated" its rather replaced – Jev Prentice Apr 23 '20 at 10:59
  • For example there exists a connection that reads this file. And this file is rather big. And OS won't let me replace file that is locked. Already have exception that says about that. I think question is more about file management while accepting connections. Like creating new copies and then cleaning unused. I think about using controller logic but not direct link, so I could manage file copies – MichaelD Apr 23 '20 at 11:08