Magercises: File I/O


Introduction

Welcome to the File I/O Magercises. These Magercises cover the most common file I/O operations such as reading lines of text and writing to text streams. The fundamental goal of these Magercises is to make you familiar with streams and stream filters. We also demonstrate how to attach streams to files on foreign machines via URLs.

There are 3 thread Magercises to complete:

  1. Streams of primitive elements.
    Write out a number of elements of primitive type and read them back in, printing them to standard output.

    Educational goal(s):

    • Learn about FileInputStream and the DataInputStream and DataOutputStream filters.

  2. Text streams.
    Print strings and primitive types to a text stream, read the information back as text, and do the conversions to the appropriate primitive types.

    Educational goal(s):

    • Learn about PrintStream and text streams.
    • Learn about StringInputStream and reading input from string sources instead of files.

  3. Read a file on another machine.
    Open a stream to a URL and display the contents.

    Educational goal(s):

    • Learn about the URL class.


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