• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Merge Files

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone tell me how to merge two files?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First figure out how to open one file. Maybe write its contents to the console. Consult the Java Tutorial if you don't know how. Then figure out how to write a file out. Consult above tutorial. Then introduce the second file and the logic to compare the two inputs record by record, writing them in sorted order to the output file.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use java.io.FileOutputStream.
It has a constructor with the signature
FileOutputStream(File file, boolean append) !
guess you can do the rest.
 
rose hegde
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i am new to know about merging files.So can u pls tell me from scratch?
Thanx
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You aren't going to make me repeat myself, are you?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a common and age-old problem. In fact, I seem to type these few lines a lot of times here. I've been doing this since ... well, a long time.

This works on any two lists that are ordered on the same key, such as master file and updates or two purchased lists of e-mail addresses for spamming or whatever. I've used it with files, result sets, arrays, etc.
This doesn't show complete "end of file" logic. One trick is at end of one file set its key impossibly high. Then the comparisons will work out to process the rest of the other file. Another is to modify the tests to say "If B.eof or A.Key < B.Key ..."
We try not to give complete answers some times, but let you figure most of it out yourself. Let me know if that's enough detail, or going the right direction at all.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rose hegde:
Can anyone tell me how to merge two files?


here's a very simple one.
remember that you have to catch the exceptions

it is not necessary that you have to use a buffer of 1 byte.
you may adjust its length and have to change the loop's condition
as well...
hope this helps.
mavedrive;
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic