Can't delete file after writing to it
<p>I have a problem with deleting the file after I wrote to it. Here is the code of writing to it:</p>

<pre><code>String xml = "blablaxml";
Path file = Paths.get("file.xml");
Files.write(file, xml.getBytes());
</code></pre>

<p>Here I want to delete it:</p>

<pre><code>Files.deleteIfExists(file);
</code></pre>

<p>The error:</p>

<pre><code>java.nio.file.FileSystemException: file.xml: The process cannot access the file because it is being used by another process.
</code></pre>

<p>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.</p>