2 Replies Latest reply: Jul 29, 2007 9:33 AM by camickr RSS

    File.delete() problem

    807605
      I have a problem with deleting files using Java 1.6. I have read all the forums on this problem and I tried all the suggestions but the problem is still there.

      In my program I am moving a file to another directory and then deleting the old file. After running my program the file is moved but the old one is still there.

      Things I have done to try and solve the problem:
      1) close all the streams
      2) assigned null to the streams
      3) checked if the file exists before I try to delete it
      4) called System.gc() before and after deleting the file (this works occasionally)

      Can anybody please tell me how to delete a file securely?
        • 1. Re: File.delete() problem
          800282
          Then there is probably some other process doing something to that file so that your Java application cannot delete it. Try to check if/what process is doing this by downloading some "process-explorer". Use Google to find one for your OS.
          • 2. Re: File.delete() problem
            camickr
            I tried all the suggestions but the problem is still there.
            Then you haven't implemented the suggestions correctly.

            If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",
            see http://homepage1.nifty.com/algafield/sscce.html,
            that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

            Don't forget to use the "Code Formatting Tags",
            see http://forum.java.sun.com/help.jspa?sec=formatting,
            so the posted code retains its original formatting.

            If you post your code then we can tell if its a logic problem or a version problem...