File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes move file A to file B Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "move file A to file B" Watch "move file A to file B" New topic

move file A to file B

Ronnie Phelps
Ranch Hand

Joined: Mar 12, 2001
Posts: 329
Does anyone have any suggestions on the bestway of replacing the contents of one file with the contents of another...given that both files exist.
Ryan Langley
Ranch Hand

Joined: May 10, 2001
Posts: 46
The default behavior of the File IO streams is to overwrite what was already in the file. IF you want to append, you have to specifically flag it in the constructor to do so. If the data is important to keep around, or is needed for auditing or something, then I would make a back-up copy of the file before you overwrite it. You can use whatever schema you want for that, and it depends on how long you want to keep back-up copy's around. Here is a basic app that I wrote up real quick to show some of the ways you can use File IO. Hope this helps in answering your question!


Ronnie Phelps
Ranch Hand

Joined: Mar 12, 2001
Posts: 329
Thanks Ryan..that was really helpful!! I need to brush up on my I/O knowledge. :-)
I agree. Here's the link:
subject: move file A to file B
It's not a secret anymore!