StreamTokenizer Tokenize Stream


Second Program: Printing File contents

File Name: Certification.txt

SCJP certification adds value to your resume.

The above file Certification.txt contents are read and printed.

import java.io.*;
public class FileTokens
{
  public static void main(String args[]) throws IOException
  {
    FileReader freader = new FileReader("Certification.txt");
    StreamTokenizer st = new StreamTokenizer(freader);

    while(st.nextToken() != st.TT_EOF) // if the token is not end-of-file marker
  {
     if(st.ttype == st.TT_WORD)     // if the token is word
     {
       System.out.println(st.sval );	  
     }
  }
 }
}	

StreamTokenizer Tokenize Stream

Certification.txt file is tokenized and in a for loop each token is read. The value returned by the nextToken() method is implicitly stored in sval and printed at DOS prompt.

5 thoughts on “StreamTokenizer Tokenize Stream”

    1. resetsyntax() it is a method
      This method resets this tokenizer’s syntax table so that all characters are “ordinary.” See the ordinaryChar method for more information on a character being ordinary.

Leave a Comment

Your email address will not be published.