title: Can't delete file after being renamed (file is opened)
body: <p>I am using <strong>icefaces</strong> to upload files to relative path in my web app <code>(mywebapp/audio)</code>, then after the file is getting uploaded I rename it to save its extension as follows:</p>
  
  <pre><code>public static File changeExtToWav(FileInfo fileInfo,
              StringBuffer originalFileName) {
          log.debug("changeExtToWav");
          int mid = fileInfo.getFile().getName().lastIndexOf(".");
          String fileName = fileInfo.getFile().getName().substring(0, mid);
          originalFileName.append(fileName);
          log.debug("originalFileName: " + originalFileName);
          String newFileName = fileName + "_" + new Date().getTime() + "."
                  + "wav";
          File newFile = new File(fileInfo.getFile().getParent() + "/"
                  + newFileName);
          log.debug("newFileName: " + newFile.getName());
          fileInfo.getFile().renameTo(newFile);
          return newFile;
      }
  </code></pre>
  
  <p>after the file is getting uploaded, sometimes I want to delete it from UI button as follows:</p>
  
  <pre><code>try {
  
              File fileToDelete = new File(filePath); // correct file path
              log.debug("file exists: " + fileToDelete.exists()); // true
              fileToDelete.delete();
          } catch (Exception e) {
              e.printStackTrace();
          }
  </code></pre>
  
  <p>the file path is correct, and I get no exceptions, but the file is not deleted (I am using java 6 btw).
  please advise how to fix this issue.</p>
  
  <p><strong>UPDATE:</strong> using the following useful method, I can get that the <strong>file is opened</strong>, any ideas how to close it ?</p>
  
  <pre><code>public String getReasonForFileDeletionFailureInPlainEnglish(File file) {
      try {
          if (!file.exists())
              return "It doesn't exist in the first place.";
          else if (file.isDirectory() &amp;&amp; file.list().length &gt; 0)
              return "It's a directory and it's not empty.";
          else
              return "Somebody else has it open, we don't have write permissions, or somebody stole my disk.";
      } catch (SecurityException e) {
          return "We're sandboxed and don't have filesystem access.";
      }
  }
  </code></pre>