Tutorial 8: Java Stream IO


Introduction

This tutorial covers:


Exercises:

  1. Copy the Java source code for all the necessary classes, ~comp212/tutorials/08/*.java, and the sample data files,  ~comp212/tutorials/08/*.txt  to your local directory:

  2. Compile FormStream.java: javac FormStream.

  3. Run FormStream with a command line argument: java FormStream dat1.txt.  Try it again with a different data file.

  4. The key method for FormStream is public ABooleanExp read() throws IOException .  It uses features of the StreamTokenizer class that comes with the java.io packag, in particular the method int nextToken () that reads one group of contiguous characters in the input stream and return an appropriate encoded integer called "token".   Review JPL chapter 12 for stream i/o in the  java.io package.

  5. The main method shows an example of  how FormStream is used in a while loop to read an ascii input file.   read() returns null when there is no more to read (i.e. end-of-file).  You can modify the main method to test your program.  For example, when you are done with semi-normal forms, you can test your conversion by reading in yur input file and printing out the converted forms.  You should leave the rest of the class FormStream alone.

D. X. Nguyen, Oct. 25, 1999.
dxnguyen@cs.rice.edu