Sunday, 11 June 2017

Java Tutorial : Java IO (Java StreamTokenizer - How to tokenize a word) ~ foundjava


Click here to watch in Youtube : 

StreamTokenizerDemo.java
import java.io.IOException;
import java.io.StreamTokenizer;
import java.io.StringReader;

public class StreamTokenizerDemo
{

    public static void main(String[] args) throws IOException
    {
        StringReader stringReader = new StringReader("Peter welcome to India");
        StreamTokenizer tokenizer = new StreamTokenizer(stringReader);
        /*
         * TT_EOL is used to determine end of line
         */
        while (tokenizer.nextToken() != StreamTokenizer.TT_EOF)
        {
            /*
             * sval-The string value of the token, if the
             * token was a string (word)
             */
            System.out.println(tokenizer.sval);
        }

    }

}
Output
Peter
welcome
to
India

Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment