Do not open and close the file stream of the output file each time you write one line. Instead open it once at the beginning and close it at the end (open/close a file stream is an expensive operation).
Put all the code in a try finally block. Close all file streams in the finally block to ensure that the streams will be closed if an exception occured.
Use TryParse instad of Parse if the format may be invalid.
If the output file already exists, the merged content will be appended (not sure if that is desired)
There are a lot of code fragements that seems to be duplicates. e.g.:
if (temp == null)
{
endOfFile1 = true;
}
else
{
item1 = Int32.Parse(temp);
}
You could extract that in a separate method
bool TryGetNextNumber(FileStream strem, out number)
{
number = -1;
var line = inputFile1.ReadLine();
if (line == null) return false;
return int.TryParse(line, out number);
}
Maybe there is also a more elegent solution than the 3 while loops... I have to think about it...