Java Reference
In-Depth Information
iif ( av . length == 0 )
new
new ScanStringTok (
new
new InputStreamReader ( System . in )). process ();
else
else
for ( int
int i = 0 ; i < av . length ; i ++)
new
new ScanStringTok ( av [ i ]). process ();
}
/** Construct a file scanner by name */
public
public ScanStringTok ( String fileName ) throws
throws IOException {
is = new
new LineNumberReader ( new
new FileReader ( fileName ));
}
/** Construct a file scanner by existing Reader */
public
public ScanStringTok ( Reader rdr ) throws
throws IOException {
// no point adding another level of buffering, if already
// being buffered...
iif ( rdr instanceof
instanceof LineNumberReader )
is = ( LineNumberReader ) rdr ;
else
else
is = new
new LineNumberReader ( rdr );
}
protected
protected void
void process () {
String s = null
null ;
try
try {
while
while (( s = is . readLine ()) != null
null ) {
StringTokenizer st = new
new StringTokenizer ( s , "@" , true
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
catch ( NoSuchElementException ix ) {
System . err . println ( "Line " + is . getLineNumber () +
": Invalid input " + s );
} catch
catch ( IOException e ) {
System . err . println ( e );
}
Search WWH ::




Custom Search