Until the stream f1
is closed, the contents that have been written to it may reside in a buffer. If this happens, the last call to show
will display the old contents of the file or (maybe worse) an incomplete version of the new contents.
Flushing could do the trick, as Ed Heal suggests in his answer, but I think that the proper way to do this is to close stream f1
as soon as the writing finishes. (Same for f2
, if you like.) Add the following lines just after the while
loop and before the last call to show
:
f1.close();
f2.close();