This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes I/O and Streams and the fly likes Join 2 files. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Join 2 files." Watch "Join 2 files." New topic
Author

Join 2 files.

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Does anyone know how to join 2 files into 1 bigger file. Say an AVI file? I know how to copy one file from one location to another, but I want to copy two files into one file.
Thanks.


GenRocket - Experts at Building Test Data
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
FileOutputStream and FileWriter both have constructors which allow you to specify a boolean argument. If set to true you open in "append" mode, so newly-written bytes are added to the end of an existing file. (Otherwise the default is to overwrite any existing file.) So you can copy the first file to its new location (or leave it in place if you prefer.) Then read from the second file, and use a Writer or OutputStream in append mode to add what you've read to the first file.


"I'm not back." - Bill Harding, Twister
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Wow, I thought that was only when appending to a text type file. Not actually making binary files into 1.
 
Consider Paul's rocket mass heater.
 
subject: Join 2 files.