Tutorial 8: Java Stream IO
Introduction
This tutorial covers:
- Java StreamTokenizer
- Class FormStream to read data files for project #1.
Exercises:
- 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:
- Compile FormStream.java: javac
FormStream.
- Run FormStream with a command line argument: java FormStream dat1.txt. Try it again with a different
data file.
- 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.
- 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