 |
File Input and Output: Open and
Save
This program shows how to use the Save and Open Dialog
Components to write numbers to and read numbers from a file. When you
press "Compute," the squares, cubes, sines and cosines of the
numbers from 0 to 9 will be calculated. When you press "Save,"
the results will be written to a file. When you press "Open,"
the results will be read from a file and rendered to the Canvas. The final
screen cannot be rendered if the file has not been written to and read.
Once you have created the file, examine its format in both a text and
binary editor and see how it corresponds to the source code. Numbers are
separated by blanks (SP). Sets of numbers are separated by the end-of-line
mark (EOL) which is actually a carraige return (CR) and a line feed (LF).
Executable
Source Code
|