title: java Cannot delete file, being used by another process
body: <p>I have this code</p>
  
  <pre><code> import org.apache.commons.io.FileUtils;
      try {
          FileUtils.copyURLToFile(new URL(SHA1_LINK), new File("SHA1.txt"));
          if(!sameSha1()) {
              System.out.println("sha diferentes");
              FileUtils.copyURLToFile(new URL(LINK), new File(PROG));
          }
      } catch (Exception e) {
          System.out.println("Internet is off");
      }
      //delete SHA1 file
      Files.deleteIfExists(Paths.get("SHA1.txt"));
  </code></pre>
  
  <p>and when I execute it it says</p>
  
  <blockquote>
    <p>java.nio.file.FileSystemException<br>
    The process cannot access the file because it is being used by another process (in sun.nio.fs.WindowsException)</p>
  </blockquote>
  
  <p>In the <code>sameSha1()</code> I have this: </p>
  
  <pre><code>String sha1Txt = new Scanner(new File("SHA1.txt")).useDelimiter("\\Z").next();
  </code></pre>
  
  <p>I want to delete the file 'SHA1.txt'. How can I do this?</p>