This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi