Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1231492

FIle.delete() will not remove directories

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1
    • CPU:
      sparc
    • OS:
      generic, solaris_2.4
    • Verification:
      Verified

      Description

      Fixed in 1.1 - File.delete() removes directories which are empty.

      -------------------------------------

      FIle.delete() only removes files, not directories. There is currently no way
      to remove a directory until this is fixed.

      --------------------------------------

      In a shell, removing a file (rm) is intentionally different from removing
      a directory (rmdir) and further the directory usually must be empty (without
      a flag). This prevents disaster, and I believe that the semantic difference
      ought to be preserved in the java API. So I recommend a method rmdir() be
      added to the File class interface.

      The upcoming 1.0.2 release is only bug fixes, with no changes to existing API.
      Any changes to API will be released in 1.1.

      -Dave Brown

      ###@###.###

      The description field as copied from bug report 1242632 follows:

      From ###@###.### Mon Mar 18 15:55:00 1996
      Date: Mon, 18 Mar 1996 15:52:24 -0800
      From: ###@###.### (Arthur van Hoff)
      To: pavani@Eng
      Subject: File.delete()
      Mime-Version: 1.0


      Hi Pavani,

      It is currently impossible to delete directories from Java.
      The delete() method in java.io.File does not delete the directory
      when the File object refers to a directory (even when it is empty).
      This leaves no alternative way to delete a directory.

      Can you please file a bug against this? It would really help us
      if this gets fixed. I've attached a test program. Thanks!

      Have fun,

      Arthur van Hoff

      -----Test--------------------

      import java.io.File;

      public class Test {
          public static void main(String argv[]) {
      File f = new File(argv[0]);
      System.out.println("mkdir = " + f.mkdir());
      System.out.println("delete = " + f.delete());
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              djbrown David Brown (Inactive)
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: