FileDocCategorySizeDatePackage
ScanStreamTok.javaAPI DocExample1435Fri Aug 31 21:12:06 BST 2001None

ScanStreamTok

public class ScanStreamTok extends Object
ScanStreamTok - show scanning a file with StringTokenizer.
author
Ian Darwin, ian@darwinsys.com
version
$Id: ScanStreamTok.java,v 1.4 2001/09/01 00:12:07 ian Exp $

Fields Summary
protected StreamTokenizer
tf
Constructors Summary
public ScanStreamTok(String fileName)
Construct a file scanner by name

		tf = new StreamTokenizer(new FileReader(fileName));
	
public ScanStreamTok(Reader rdr)
Construct a file scanner by existing Reader

		tf = new StreamTokenizer(rdr);
	
Methods Summary
public static voidmain(java.lang.String[] av)

		if (av.length == 0)
			new ScanStreamTok(
				new InputStreamReader(System.in)).process();
		else 
			for (int i=0; i<av.length; i++)
				new ScanStreamTok(av[i]).process();
	
protected voidprocess()

		String s = null;
		int i;

		while ((i = tf.nextToken()) != tf.TT_EOF) {
			switch(i) {
			case StreamTokenizer.TT_EOF:
				System.out.println("End of file");
				break;
			case StreamTokenizer.TT_EOL:
				System.out.println("End of line");
				break;
			case StreamTokenizer.TT_NUMBER:
				System.out.println("Number " + tf.nval);
				break;
			case StreamTokenizer.TT_WORD:
				System.out.println("Word, length " + tf.sval.length() + "->" + tf.sval);
				break;
			default:
				System.out.println("What is it? i = " + i);
			}
		}