FileDocCategorySizeDatePackage
ScanStringTok.javaAPI DocExample1623Mon Feb 16 18:17:56 GMT 2004None

ScanStringTok

public class ScanStringTok extends Object
ScanStringTok - show scanning a file with StringTokenizer.
author
Ian Darwin, http://www.darwinsys.com/
version
$Id: ScanStringTok.java,v 1.4 2004/02/17 00:17:55 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);
		}