Hi guys, Below is the code where i read a RandomAccessFile (RAF) and search for a string and insert a line at the particular location. I do this by creating 2 RAF's. The new RAF ( arrayfile2, in the code below)is the resulting file with the inserted string, I am trying to rename the arrayfile2 to arrayfile1 , but the rename always return false. I am not sure why rename is not successful. I checked for the permissions of the file, full permission is there. I closed the files before renaming.
Please let me know whats wrong with the above code. I have no clue why renameTo returns false. Thanks, Priyha
Probably because the original arrayfile1 still exists. The system won't let you have two files with the same name. Execute arrayfile1.delete() first (and check the return value to make sure it worked) then try the rename.
HI, I support JIM, the renameTo() method is basically platform depenedent (on File system). But what Jim said is right. If a file already exists with the name then renameTo() returns false. Cheers, Gaya3
Joined: Sep 13, 2001
yes Jim , you are absolutely right, it worked now. I dont know why it didn't come to my mind before, i really appreciate your help. Thanks a lot, Priyha.
Joined: Jan 30, 2000
I really wish they had written renameTo() and delete() to throw an exception when they fail, with a message explaining why. It would save people a lot of grief...