I have a problem with deleting the file after I wrote to it. Here is the code of writing to it:
String xml = "blablaxml";
Path file = Paths.get("file.xml");
Files.write(file, xml.getBytes());
Here I want to delete it:
Files.deleteIfExists(file);
The error:
java.nio.file.FileSystemException: file.xml: The process cannot access the file because it is being used by another process.
I debugged the code and just before trying to delete the file I used Microsoft Process Explorer and the file is not used by any process, so I don't understand the error.