Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Java by Comparison (eBook) this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Join 2 files.  RSS feed

 
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, I thought that was only when appending to a text type file. Not actually making binary files into 1.
 
You didn't tell me he was so big. Unlike this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!