
Opening a file for writing
will cause the existing file
data to be deleted.If you
intend to add new data to
a file while maintaining
the original contents,open
the file for appending.
COMMON ERROR
TRAP
11.4 Reading Structured Text Files 767
writing to it. If the file output.txt exists, we will start writing at the end of
its current contents, whereas if the file does not exist, it will be created.
In this program, we append four additional lines to the file (lines 21–29).
Assuming that before this program is executed, the file output.txt contains
the poem shown in Figure 11.14, then after this program is executed, the
file output.txt will contain the te