10 Replies Latest reply: Feb 24, 2009 12:40 PM by 807588 RSS

    File not getting deleted using File.delete()

    796745
      Hi guys,

      I have a code like this:
      File tempdir = new File("tempdir");
      tempdir.mkdir();
      File temporaryFile = new File("tempdir\tempfile.txt");
      FileWriter writer = new FileWriter(temporaryFile);
      // write data into file
      writer.flush();
      writer.close();
      try {
          // Do something
      }
      catch (Exception e) {
          // Do something
      }
      temporaryFile.delete();
      tempdir.delete();
      The program runs successfully. The directory and the file is created and data is written successfully into it. However, the file as well as directory is not getting deleted at the end of the program. I tried temporaryFile.deleteOnExit(), but this also didn't help.

      Can anyone provide some input as to what can be the possible reasons for the file not getting deleted?

      Thanks..