Text streams


Write a series of lines to a text file and read them back in, verifying their consistency.

Details of input and output streams are covered in the course notes.

Work Location

Perform all work for this magercise in VisualAge project MageLang Magercises, package magercises.Text Streams.

If this project does not appear in your Workspace add it from the repository (if it exists there) or create a new project using this name.

Tasks

Perform the following tasks:

  1. Create a PrintStream on file junk. Write the following out to a text file:
    34
    "an int is " + 34
    3.14159
    true
    

  2. Close the file and open a FileInputStream to junk. Read the four lines back in.

  3. Verify that the four lines read in contain the correct values by first converting the strings (all but the third line) to primitive types. Print "ok" for all correct lines and "not ok" for all incorrect lines.

The task numbers above are linked to the step-by-step help page. Also available is a complete solution to the problem, and expected behavior, to demonstrate it.

Copyright © 1996-1997 MageLang Institute. All Rights Reserved.