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

Method File.renameTo(File dest) does not work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P1 P1
    • None
    • 1.1
    • core-libs
    • sparc
    • solaris_2.4

      Follows is the test program that demonstrates problem. Check
      directory for file "FileName.new". Instead you find file "Filename.tmp"
      that means that rename failed. Also notice that you will see
      "Operation Successfull = : true" i.e. method renameTo() returned true.
      While no file is renamed.

      --------------8<----- TestFileRename.java ------------------------import java.io.*;


      public class TestFileRename {
        
        public static void main(String[] argv) {
          try {
            File tmpFile = new File("Filename.tmp");
            FileOutputStream fout = new FileOutputStream(tmpFile);
            
            System.getProperties().save(fout, "TmpFile Testing Rename");
            fout.close();
            // Create Dest file
            File dest = new File("FileName.new");
            System.out.println("Operation Successfull = : " + tmpFile.renameTo(dest));
            if (dest.exists())
      System.out.println("File Renamed to:" + dest.toString());
            else
      System.out.println("Rename Filed");
          }
          catch (Exception e) {
            e.printStackTrace(System.out);
          }
        }
      }
            

            nishimur Naoyuki Ishimura (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: