I have a file I need to rename to that of an existing file. This is a copy, modify, replace original operation on an existing JAR file. I've got the first two steps done, I just need help with the replace original bit. What's the best way to rename the new version of the JAR to that of the old. The old JAR doesn't need preserving and I don't want to have a copy of the new with its initial name sticking around.
I have commons lang and io already, so if there's a method I've missed, that would be great.
Java.io.File.renameTo(java.io.File)
You might need to call File.delete() first on the original file first - some systems won't rename a file onto an existing file.
You're going to need to create two java.io.File objects: one for the new file, one for the old file.
Lets call these oldFile and newFile.
oldFile.delete()
newFile.renameTo(oldFile);
Edit: mmyers beat me to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With