There is xml, which I open for editing on java.
How to make so that at the time of work tulza, no one else could edit the file?
Addition: It is necessary to take into account that the tool may be terminated abnormally, therefore file.setWritable(false) probably not work (the file will remain locked)
Unfortunately, the option
Runtime.getRuntime().addShutdownHook(new Thread(() -> { file.setWritable(true); })); It does not work, because if, while the program is running, it is abnormally terminated, the file remains read only.