This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Unable to rename file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Unable to rename file" Watch "Unable to rename file" New topic
Author

Unable to rename file

Siddhesh Khedekar
Ranch Hand

Joined: Nov 09, 2009
Posts: 36
Hi Experts,

I am tryin following code -


The folder D:\test already exists.
but not able to rename the file and getting output

Results.dat
Results.dat
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

File.renameTo does not change the File object. If it returns true it renames the file, yes, but the File object is immutable and stays exactly the same. Instead of using the old value of f you should reassign it:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to rename file
 
Similar Threads
file.renameTo() fails
rename file
Renaming a file -- what's wrong with this code ?
Writing to a file in Java..?
File rename/delete