9 Replies Latest reply on Mar 19, 2010 2:44 AM by 3004

    Deleting a file Exception


      Im using code like the below....
      File dir = new File(newDir);
               // Make sure the file or directory exists and isn't write protected
               if (!dir.exists())
                 throw new IllegalArgumentException(
                     "Delete: no such file or directory: " + fileName);
               if (!dir.canWrite())
                 throw new IllegalArgumentException("Delete: write protected: "
                     + fileName);
               // Attempt to delete it if already exists
                    boolean success = newFile.delete();
                     if (!success)
                          throw new IllegalArgumentException("Delete: deletion failed");
      which throws the exception from the lasrt line, saying deletion failed. Im a little confused as I cant see why its fails, as it checks if it has permission to write to disk (which i presume is the same as permission to delete), and the file does exist (it checks for that also).

      Can anyone please enlighten me?

      Thanks :)