The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Now you can read your IP addresses

Posted by Kishori Sharan on December 11, 2000 at 11:32 AM

The StreamTokenizer is, by default, set to tokenize sophisticated java programs. So first thing you need to do is to reset the sepecialized synatax by calling resetSyntax ( ) method and set your own delimiter chars, white spaces etc. Here is the example which will read your IP addresses from text file. Just replace the file path C:\\kishori\\ip.txt to your own.

Thanx
Kishori

////////////////////C.java ////////////////
import java.io.*;

public class C {
private static StreamTokenizer st;
public static void main ( String[] args ) throws Exception {
st = new StreamTokenizer( new BufferedReader(new FileReader("c:\\kishori\\ip.txt")));

st.resetSyntax ( ) ;
st.whitespaceChars ( 0, ' ' ) ;
st.wordChars ( 33, 255 ) ;
String s = "";

while( st.nextToken() != StreamTokenizer.TT_EOF) {

if ( st.ttype == StreamTokenizer.TT_WORD ) {
s = st.sval ;
}
System.out.println ( s ) ;
}
}
}




Replies:
  • Thanks Yaron Berman December 12, 2000 at 1:29 AM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us