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

java.io.File.renameTo() does not work properly under Windows95

XMLWordPrintable

    • x86
    • windows_95



      Name: akC57697 Date: 07/08/98



         The pair File.renameTo()/File.exists() does not work properly with
       specific filenames under Windows95.
         The example below verifies the first file is absent and second file
       exists after f1.renameTo(f2). It works under Solaris and WindowsNT
       but does not work correctly under Windows95 with some filenames.
         Actually, only second file exists on a disk after the test has
       finished but File.exists() returns true for both files after the renaming.

       The documentation says:
      "
      public boolean exists()

      Tests whether the file denoted by this abstract pathname exists.
      return true if and only if the file denoted by this
      abstract pathname exists; false otherwise

      public boolean renameTo(File dest)

       Renames the file denoted by this abstract pathname.
       return true if and only if the renaming succeeded;
       false otherwise
      "
       
       
      The example:
      ------------------------------8-<--------------------------------------------
      import java.io.File;

      class FTest {
        public static void main(String[] argv) {

          File f1 = new File("filename");
          File f2 = new File("filename_copy");
          long len=0;

          // Create the file
          try {
           java.io.FileOutputStream fo = new java.io.FileOutputStream(f1);
           fo.write(1);
           fo.write(1);
           fo.write(1);
           fo.close();
          } catch (java.io.IOException e) { System.out.println("Unexpected:"+e);}
          
          // Rename
           System.out.println(f1.getPath()+" rename to "+f2.getPath());

           if (f1.renameTo(f2))
            if ((!f1.exists()) && f2.exists() && f2.isFile() ) {
             System.out.println("OKAY"); }
            else {
             System.out.println("The first file:"+f1.getPath()+" exists :"+f1.exists());
             System.out.println("The second file:"+f2.getPath()+" exists :"+f2.exists());
            }
         }
      }
      ---------------------------->-8----------------------------------------------
      Windows95
      The statistics:
      File2042 -> File2042_1 does not work
      File2042 -> File2042_copy does not work
      12345678.ext -> 12345678_c.ext does not work
      filename -> filename_copy does not work

      File2042_1 -> File2042_2 works
      File -> File_copy works
      0123456789 -> 0123456789_copy.ext works
      123.ext -> 123.ext.copy works
      filename123 -> filename123_copy works


      Fails:
      C:\temp>
      java.exe full version "JDK-1.2fcs-A"
      C:\temp>g:\JDK1.2-fcsA\windows\bin\java FTest
      filename rename to filename_copy
      The first file:filename exists :true
      The second file:filename_copy exists :true

      Passes:
      C:\temp>
      java.exe full version "JDK-1.2fcs-A"
      C:\temp>g:\JDK1.2-fcsA\windows\bin\java FTest
      filename123 rename to filename123_copy
      OKAY



      ======================================================================

            bgomessunw Benedict Gomes (Inactive)
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: