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

File.delete() doesn't work with same name used for File.mkdir() on Windows

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.2
    • core-libs
    • None
    • sparc
    • solaris_2.5.1

      On Windows, certain filenames (which are technically not correctly constructed) will work with some calls, but not others. Here's some example code:

      import java.io.*;
      public class FSTest {
        public static void main(String[] args) {
              File testDir1 = new File("/\\c:\\WINDOWS\\TEMP\\A");
              System.out.println(testDir1);
              System.out.println(testDir1.mkdir());
              System.out.println(testDir1.delete());
        }

      This code will create "A" in the temp folder, but delete will return false. File.Rename() will not work on "A" either (there may be other calls too). It's all because of the "\" in the front of the name. Normally, the workaround would be not to put the "\" in front, but URL.getFile prepends a "\" for some reason (see related bug), so getting a filename like this is more common than you might think.

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: