The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A doubt about renaming a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A doubt about renaming a file" Watch "A doubt about renaming a file" New topic

A doubt about renaming a file

Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Hi all ,
I have been learning manipulating files using package .I have some doubts in the following program which I tried .

Everything goes fine when I run very first time but I run more than once(with out deleting the previously created directory )
renaming didn't occur as I expected instead it creates another file named "file1.txt"(which I expect will be renamed as "newFile.txt").

What is happening ? .Please clarify me .

Thanks in advance
Henry Wong

Joined: Sep 28, 2004
Posts: 20152

Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.

Here is the quote from the Javadoc for the renameTo() method. Do you think that it has anything to do with the fact that the rename target already exists?


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Henry , Thanks for your reply which cleared my doubt.
[ May 03, 2008: Message edited by: Parthiban Mahiby ]
I agree. Here's the link:
subject: A doubt about renaming a file
jQuery in Action, 3rd edition