title: How to delete an image in Java after renaming the file and delete the original file?
body: <p>I got a problem when i want to update my (lets say orderNumber) and i try to renaming the file of image. lets say the original file ini MainImage15 i want to rename to MainImage16 with Files.Copy or Files.Move and after that i try to delete after succesful copying. and i got the error like this</p>
  
  <pre><code>java.nio.file.FileSystemException: C:\Users\User\apache\webapps\Promotion\030000\MainImage15.jpg: The process cannot access the file because it is being used by another process.
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>public void renameFileToFileSystem(final String fileName, final String oldFileLocation, final String newFileLocation) {
      Path source = Paths.get(oldFileLocation);
      Path destination = Paths.get(newFileLocation);
      try {
          Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
          Files.delete(source);
      } catch (final IOException ioException) {
          throw new ContentManagementException(fileName, ioException.getMessage());
      }
  }
  </code></pre>
  
  <p>i dont knwo what to do. should i use buffer close? but i just renaming the file . thankyou.</p>