FileDocCategorySizeDatePackage
ScanStringTok.javaAPI DocExample1634Sat Nov 25 12:55:32 GMT 2000None

ScanStringTok

public class ScanStringTok extends Object
ScanStringTok - show scanning a file with StringTokenizer.
author
Ian Darwin, ian@darwinsys.com
version
$Id: ScanStringTok.java,v 1.2 2000/11/25 17:55:32 ian Exp $

Fields Summary
protected LineNumberReader
is
Constructors Summary
public ScanStringTok(String fileName)
Construct a file scanner by name

		is = new LineNumberReader(new FileReader(fileName));
	
public ScanStringTok(Reader rdr)
Construct a file scanner by existing Reader

		// no point adding another level of buffering, if already
		// being buffered...
		if (rdr instanceof LineNumberReader)
			is = (LineNumberReader)rdr;
		else
			is = new LineNumberReader(rdr);
	
Methods Summary
public static voidmain(java.lang.String[] av)

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

		String s = null;
		try {
			while ((s = is.readLine()) != null) {
				StringTokenizer st = new StringTokenizer(s, "@", true);
				String user = (String)st.nextElement();
				st.nextElement();
				String host = (String)st.nextElement();
				System.out.println("User name: " + user +
					"; host part: " + host);

				// Presumably you would now do something 
				// with the user and host parts...  

			}

		} catch (NoSuchElementException ix) {
			System.err.println("Line " + is.getLineNumber() +
				": Invalid input " + s);
		} catch (IOException e) {
			System.err.println(e);
		}